Q:Form1上一个Button点击后弹出新窗口Form2,在新窗口点击Button如何控制Form1中的某些控件?
A:用委托。一个简单可行的办法用ref.下面是个小例子:
在Form1的button1_Click里写:
private void button1_Click(object sender, EventArgs e)
{
this.button1.Enabled = false;
Form2 f2 = new Form2(ref button1);
f2.Show();
}
Form2里这样写:
public Button button;
public Form2(ref Button button)
{
this.button = button;
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.button.Enabled = true;
}
2019-12-21 19:43:50
716B
C#
控件调用
1