控件委托事件,将一个控件的事件绑定到另一个控件
定义btnAdd事件:
private void btnAdd_Click(object sender, EventArgs e) { frmNodeItem nodeItem = new frmNodeItem(); if (this.MenuList.FocusedNode.ParentNode == null) { nodeItem.LoadStuData(this.MenuList.FocusedNode); nodeItem.LoadClass(ManageSystem.BLL.ClsService.GetAllClsName()); if (nodeItem.ShowDialog()==DialogResult.OK) { this.MenuList.BeginUpdate(); string NodeName=nodeItem.m_SelectClsName; TreeListNode node = this.MenuList.AppendNode(new object[] { null, null, NodeName }, MenuList.FocusedNode); if (node != null) { MessageBox.Show("【" + NodeName + "】节点添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.MenuList.EndUpdate(); } } else { MessageBox.Show("请选择正确的节点进行操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
需要绑定btnAdd事件的控件:
private void tsmAdd_Click(object sender, EventArgs e) { btnAdd_Click(this.tsmAdd, e); }