频道直达 - 学院 - 下载 - 交易 - 特效 - 字库 - 手册 -排名-工具- 繁體
网页教学网站开发 设为首页
加入收藏
联系我们
建站搜索: 常用广告代码   用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发设计技术教程 -> asp教程 -> 通过事件,在两窗体间传递数据

通过事件,在两窗体间传递数据

作者:未知  来源:转载  发布时间:2005-7-20 11:13:50  发布人:acx

减小字体 增大字体

 
//---------------------------------------
// 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;
}

}
}

}



将本文收藏到QQ书签与更多好友分享
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 要10G免费网络硬盘的请进..
· 通过google 赶快来赚美金..
· 注册码大全十
· 头像-qq头像(qq新头像)4..
· 让你轻松架设FTP服务器1..
· 注册码大全三
· 梦幻背景图片7
· 卡通动物图片6
· 网页制作素材-按钮素材2..
· 让你轻松架设FTP服务器5..
· 风景图片8
· 注册码大全九
· 让你轻松架设FTP服务器2..
关注此文读者还看过
· replace不区分大小写(高..
· 我做的一个迷宫游戏(图..
· 操作系统进程描述2
· 用代码实现ListView控件..
· 伦敦MeCompany网站设计师..
· 如何防止IE缓存jsp文件
· Flash MX2004入门与进阶..
· ASP.NET中在线用户统计的..
· 拿什么拯救你 痴迷网站的..
· 程序员眼中的Flash MX20..
· 网络搜索引擎公司谷歌每..
· Flash与虚拟实境
· 两种没有使用绑定的 数据..
· 处理任何传进来的表单Fo..
· .NET之对接口和抽象类
· 可爱小女孩的照片润色攻..
相关文章
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
粤ICP备05092265号