帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
通过事件,在两窗体间传递数据
作者:sunsg 发布时间:2005-03-12 来源:开发者俱乐部
//---------------------------------------
// form1.cs
//----------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace FormConmunicate
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>

public delegate string getText();

public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(64, 40);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(88, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 168);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 24);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
//this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.textBox1});


FormHandel.myFormHandel[0]=(int)this.Handle;


this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Form1 f1=new Form1();
Form2 f2=new Form2();

f2.TextChange+=new TextChangeEventHander(f1.ontextchange);

f2.Show();

Application.Run(f1);
}

private void ontextchange(object sender,Form2EventArg e)
{
this.textBox1.Text=e.MyText ;

}
}

public class FormHandel
{
public static int[] myFormHandel={1,2};

}

}

//-----------------------------------------------
// form2.cs
//-----------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace FormConmunicate
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
///

public delegate void TextChangeEventHander(object sender,Form2EventArg e);

public class Form2 : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;

public event TextChangeEventHander TextChange;

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;


public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

this.textBox1.Text=this.Handle.ToString();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(168, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(80, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(168, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 24);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.textBox1});

FormHandel.myFormHandel[1]=(int)this.Handle;
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{

//引发事件,并传递数据
TextChange(this,new Form2EventArg(this.textBox1.Text));
}
}

//事件数据
public class Form2EventArg:System.EventArgs
{
private readonly string mytext ;

public Form2EventArg(string str)
{
mytext=str;
}

public string MyText
{
get
{
return mytext;
}

}
}

}

  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·使用NextRecordset通过一个Conne  (2005-03-12)
 ·在asp中通过vbs类实现rsa加密与解  (2005-03-12)
 ·在asp中通过getrows实现数据库记  (2005-03-12)
 ·通过禁止使用xp_cmdShell提高安全  (2005-03-12)
 ·基于wap协议的wml开发示例,在Op  (2005-03-12)
 ·NetBeans开放源项目通过18个新模  (2005-03-12)
 ·如何用JDBC实现通过APPLET连mssq  (2005-03-12)
 ·通过对php一些服务器端特性的配置  (2005-03-11)
 ·PHP中通过ADO调用Access数据库  (2005-03-11)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统