首先先定义一个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... }