我把form1中要更改的控件设置成了public型,
在fo'r'm2中
Form1 mm = new Form1();
mm.toolStripStatusLabel1.Text = "正在读取";
form1的这个控件属性并没有变,我是初学者,请问大虾,哪位知道啊
你在Form2里写的代码是
Form1 mm = new Form1();
mm.toolStripStatusLabel1.Text = "正在读取";
也就是mm是一个新的对象,不是原来显示的Form1了
如果想要在Form2中更改From1的数据,可以使用事件向From1传输数据.
具体方法可以参考
http://www.bc-cn.net/bbs/dispbbs.asp?boardID=117&ID=47337&page=3
public delegate void MyHandler();
public class Form2 : System.Windows.Forms.Form
{
public event MyHandler MyEvent;
private void button1_Click(object sender, System.EventArgs e)
{
if (MyEvent != null)
{
MyEvent();
}
}
}
public class Form1 : System.Windows.Forms.Form
{
private void button1_Click(object sender, System.EventArgs e)
{
Form2 form2 = new Form2();
form2.MyEvent += new MyHandler(form2_MyEvent);
form2.Show();
}
private void form2_MyEvent()
{
statusBar1.Text = "Form2 Button Clicked!";
}
}