0
更改按钮属性
我想问如何从类中更改主窗体中的按钮属性。 我与button called Call
形式。此按钮是已禁用。 我有正在检查网络连接的课。我的课程何时连接我希望启用按钮从课程网络呼叫,但我无法更改此课程的属性。在主窗体中从类
代码
public class network
{
...
MainForm frm = new MainForm();
..
.
.
if(isNetwork==true)
{
frm.Call.Enabled = true; //nothing happends, button is still disabled
methodUpdate(); // second solution with calling method, but it
doesn't work too ...
}
}
的MainForm
...
public void methodUpdate()
{
Call.Enabled = true;
}
,但是当我在主要形式和方法,单击我有methodUpdate另一个按钮()所有运作良好;
button click method in MainForm
private void button1_Click(object sender, EventArgs e)
{
methodUpdate(); //this is working well
}
你调试你的代码?这听起来好像它没有进入你的if block ......你能证实它是什么吗? –
是的,正如Roryap所质疑的,你是否已经逐步完成了每行代码?我也怀疑这不会触及你的'if'陈述。 – Sean
您正在创建一个新表单。那是实际显示的那个吗?你是否从UI线程进行修改?如果是这样,你可能会阻止UI线程,从而阻止它改变按钮状态。如果不是,当您尝试从其他线程修改UI控件时,您会遇到异常。 – Luaan