我是一名业余爱好程序员。在我的C#2010 Express + SQL Server 2008桌面应用程序中,我正在尝试添加代码来单击childitem事件。我想确定这个子菜单项的父(menuitem)。我怎么能找到它?
答案 0 :(得分:1)
试试这个
private void mnuDatabase1_Click(object sender, ...)
{
ToolStripMenuItem MyMenuItem = (ToolStripMenuItem)sender;
ToolStripMenuItem parent = (ToolStripMenuItem)MyMenuItem.OwnerItem;
if (parent.Name == "mnuAdd")
//Add Menu
else if (parent.Name == "mnuEdit")
//Edit Menu
else if (parent.Name == "mnuDelete")
//Delete Menu
}