有两个窗体,一个为MDI主窗体frmMain,一个为MDI子窗体frmMDIChild,我在主窗体的一个菜单项的单击事件下对子窗体中的某个控件进行某种操作,结果什么反映都没有,运行没问题的,不知道原因出在哪里,请大家指导指导!代码如:
private void mnuFile_Click(object sender, System.EventArgs e)
{
TestTemp.frmMDIChild form1=new TestTemp.frmMDIChild();
form1.textBox1.text="welcome";
}
private void mnuFile_Click(object sender, System.EventArgs e)
{
TestTemp.frmMDIChild form1=new TestTemp.frmMDIChild();
form1.textBox1.text="welcome";
}
private void button1_Click(object sender, System.EventArgs e)
{
this.IsMdiContainer = true;
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();
this.LayoutMdi(MdiLayout.TileVertical);
}
public frmMDIChild(TestTemp.frmMain parent)
{
//通过此窗体的构造函数把此窗体的MdiParent属性设置为主窗体的一个引用
InitializeComponent();
this.MdiParent=parent;
}
public frmMain()
{
InitializeComponent(); TestTemp.frmMDIChild child=new TestTemp.frmMDIChild(this);
child.Show();
}
目前在主窗体中对父窗体中的某控件进行操作不起什么作用,但运行是没问题的
TestTemp.frmMDIChild form1= this.ActiveMdiChild as TestTemp.frmMDIChild;
form1.textBox1.text="welcome";