MDIForm工具栏中的按键事件与子窗体的btn事件

首先先定义一个interface
public interface btnClickEvent
    {
        void btnAdd_Click();       
        void btnEdit_Click();
    }

 

然后在父窗体中按键事件
private void btnAdd_Click(object sender, EventArgs e)
        {
            if (ActiveMdiChild != null)
            {
                if (ActiveMdiChild.Controls.Find("btnAdd", true).Length != 0 && ActiveMdiChild.Controls["btnAdd"].Enabled == true)
                {
                    btnClickEvent btnClickAdd;
                    btnClickAdd = (btnClickEvent)(this.ActiveMdiChild);
                    btnClickAdd.btnAdd_Click();

                }
                else
                    {}
            }
        }

最后在子窗体中继承这个interface
在cs中加 
void btnClickEvent.btnAdd_Click()
        {
            btnAdd_Click(null, null);
        }
private void btnAdd_Click(object sender, EventArgs e)
        {
            //to do...        }

posted @ 2009-04-10 10:01  奋斗, 奋斗, 奋斗!  阅读(287)  评论(0编辑  收藏  举报