C# 怎么在自定义的方法里调用窗体控件 或者 在另一个窗体里调用本窗体控件

来源:百度知道 编辑:UC知道 时间:2024/05/07 10:32:52

通过挂载事件的方式跨Form调用。
以下为在主窗体调用子窗体的TextBox2来设置主窗体Textbox1的代码:

主窗体:

private void button1_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.Closed += new EventHandler(this.CloseForm2);
frm.ShowDialog();
}

private void CloseForm2(object sender, EventArgs e)
{
Form2 frm=(Form2)sender;
if(frm.IsRefreshMain)
{
this.textBox1.Text = frm.textbox2.Text;
}
}

目前Winform编程还是要多利用事件模型的:)

上面有你想要的代码 很多 :http://www.bc-cn.net/

对方法传入参数,像你说的这些都可以实现的,但你要给控件ID