本文主要是介绍ContextMenu单击事件的解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
实例代码如下: public partial class RPAMessenger : Form ... {
private ContextMenu contextMenu = new ContextMenu();
private MenuItem menu_Exit = new MenuItem();
private MenuItem menu_Open = new MenuItem();
private void RPAMessenger_Load(object sender, EventArgs e) ...{
createIconMenuStructure();
menu_Exit.Click += new EventHandler(menu_Exit_Click);
menu_Open.Click += new EventHandler(menu_Open_Click);
}
protected void menu_Open_Click(object sender, EventArgs e) ...{
}
protected void menu_Exit_Click(object sender, EventArgs e) ...{
try ...{
Application.Exit();
} catch (Exception ex) ...{
}
}
public void createIconMenuStructure() ...{
// Add menu items to context menu.
menu_Open.Text = "&Open";
contextMenu.MenuItems.Add(menu_Open);
menu_Exit.Text = "&Exit";
contextMenu.MenuItems.Add(menu_Exit);
}
}
private ContextMenu contextMenu = new ContextMenu();
private MenuItem menu_Exit = new MenuItem();
private MenuItem menu_Open = new MenuItem();
private void RPAMessenger_Load(object sender, EventArgs e) ...{
createIconMenuStructure();
menu_Exit.Click += new EventHandler(menu_Exit_Click);
menu_Open.Click += new EventHandler(menu_Open_Click);
}
protected void menu_Open_Click(object sender, EventArgs e) ...{
}
protected void menu_Exit_Click(object sender, EventArgs e) ...{
try ...{
Application.Exit();
} catch (Exception ex) ...{
}
}
public void createIconMenuStructure() ...{
// Add menu items to context menu.
menu_Open.Text = "&Open";
contextMenu.MenuItems.Add(menu_Open);
menu_Exit.Text = "&Exit";
contextMenu.MenuItems.Add(menu_Exit);
}
}
这篇关于ContextMenu单击事件的解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!