1、属性传值
1、传值窗体定义属性
public ChildrenFrm MSg { get; set; }
2、private void ParentFrm_Load(object sender, EventArgs e)
{
ChildrenFrm chFrm = new ChildrenFrm();
MSg = chFrm; //此对象直接赋予给需要传值窗体类型属性
chFrm.Show();
}
//注意接收窗体的属性值
3private void btnMsg_Click(object sender, EventArgs e)
{
MSg.txtMsg.Text = this.txtMsg.Text;
}
2、方法传值
1、传值窗体定义属性
public ChildrenFrm MSg { get; set; }
2、private void ParentFrm_Load(object sender, EventArgs e)
{
ChildrenFrm chFrm = new ChildrenFrm();
MSg = chFrm; //此对象直接赋予给需要传值窗体类型属性
chFrm.Show();
}
3、 private void btnMsg_Click(object sender, EventArgs e)
{
MSg.StrText(this.txtMsg.Text);
} //注意方法调用
接收窗体方法
1、 public void StrText(string txt)
{
this.txtMsg.Text = txt;
}
3、委托传值
1、主窗体创建委托属性
public Action<string> ShowMsg {get;set;} //委托类型
2、 private void ParentFrm_Load(object sender, EventArgs e)
{
Children2 chFrm2 = new Children2();
ShowMsg += chFrm2.Say;
chFrm2.Show();
}
3、 private void btnMsg_Click(object sender, EventArgs e)
{
ShowMsg(this.txtMsg.Text);
}
接收窗体方法
1、 public void Say(string txt)
{
this.txtMsg.Text = txt;
}
原文:http://www.cnblogs.com/haimingkaifa/p/5329866.html