我現在是這樣控制的, 但當有多個子窗口(mdichild)時, 不知如何控制private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
int posiFlag; customers actMdiForm =this.ActiveMdiChild as customers;  //這裡指定子窗口是customers
this.BindingContext["",""].EndCurrentEdit();

switch (this.toolBar1.Buttons.IndexOf(e.Button ))
{
             case 0 :  //新增
this.mcrmconfigure.isadding=true;
settoolbarstate();

if (actMdiForm != null) 
{
actMdiForm.SetControlsState();
actMdiForm.modifyrecord();
}
break;
case 1 :  //修改
this.mcrmconfigure.isediting=true;
settoolbarstate();

if (actMdiForm != null) 
{
actMdiForm.SetControlsState();
actMdiForm.modifyrecord();
} break;
             ......

解决方案 »

  1.   

    使用foreach来遍历整个子窗体,如果是激活的话,设置它的属性
    foreach(Form f in this.MdiChildren)
    {
    if (f is frmMeRpt)
    {
    f.Focus();//做设置的动作
    }
    }
      

  2.   

    ? if (f is frmMeRpt) 這裡frmMeRpt也是一個特定的form吧, 如果有十個form, 如何處理?
      

  3.   

    给你个思路看行不行。
    1. 定义一个接口或一个基础子FORM,里面用InitToolBar, Add, Edit, Delete等方法。
    2. 所有的子FORM都实现接口或继承基础子FORM。
    3. MDIPARENT窗体的MdiChildActivate事件中将ActiveMdiChild转换为接口或基类,然后调用InitToolbar,这是初始化公共TOOLBAR的方法。
    4. 当TOOLBAR被CLICK后,也转换ActiveMdiChild为接口或基类,调用相应的方法。