http://hi.baidu.com/ivanbobo/blog/item/63571d1744ea941bc83d6ddd.html
public partial class MDI : Form
{
public delegate void PostText(string text);
public event PostText PT;
public MDI()
{
InitializeComponent();
}
private void MDI_Activated(object sender, EventArgs e)
{
MDIParent1 mdiForm = (MDIParent1)this.MdiParent;
mdiForm.statusStrip.Items[0].Text = this.Text;//当父窗体变量为公有时,直接设置更为简单
}
}
public partial class MDI : Form
{
public delegate void PostText(string text);
public event PostText PT;
public MDI()
{
InitializeComponent();
}
private void MDI_Activated(object sender, EventArgs e)
{
MDIParent1 mdiForm = (MDIParent1)this.MdiParent;
mdiForm.GetText(this.Text);//往往父窗体控件都为私有的,委托的
}
}
在MDIParent1中代码:
public partial class MDIParent1 : Form
{
private int childFormNumber = 0;
public MDIParent1()
{
InitializeComponent();
}
private void ShowNewForm(object sender, EventArgs e)
{
// 创建此子窗体的一个新实例。
MDIApplication.MDI childForm = new MDIApplication.MDI();
// 在显示该窗体前使其成为此 MDI 窗体的子窗体。
childForm.MdiParent = this;
childForm.WindowState = FormWindowState.Maximized;
childForm.Text = "窗口" + childFormNumber++;
childForm.Show();
childForm.PT += new MDI.PostText(GetText);
}
{
this.statusStrip.Items[0].Text = text;
}
}
}