本文整理汇总了C#中System.Windows.Forms.ContextMenu类的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu类的具体用法?C# ContextMenu怎么用?C# ContextMenu使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextMenu类属于System.Windows.Forms命名空间,在下文中一共展示了ContextMenu类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MyPopupEventHandler
private void MyPopupEventHandler(System.Object sender, System.EventArgs e)
{
// Define the MenuItem objects to display for the TextBox.
MenuItem menuItem1 = new MenuItem("&Copy");
MenuItem menuItem2 = new MenuItem("&Find and Replace");
// Define the MenuItem object to display for the PictureBox.
MenuItem menuItem3 = new MenuItem("C&hange Picture");
// Clear all previously added MenuItems.
contextMenu1.MenuItems.Clear();
if(contextMenu1.SourceControl == textBox1)
{
// Add MenuItems to display for the TextBox.
contextMenu1.MenuItems.Add(menuItem1);
contextMenu1.MenuItems.Add(menuItem2);
}
else if(contextMenu1.SourceControl == pictureBox1)
{
// Add the MenuItem to display for the PictureBox.
contextMenu1.MenuItems.Add(menuItem3);
}
}
示例2: new ContextMenu()
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class ContextMenuAdd: Form
{
MenuItem miColor;
public static void Main()
{
Application.Run(new ContextMenuAdd());
}
public ContextMenuAdd()
{
Text = "Context Menu Using Add";
ContextMenu cm = new ContextMenu();
EventHandler eh = new EventHandler(MenuColorOnClick);
cm.MenuItems.Add("Black", eh);
cm.MenuItems.Add("Blue", eh);
cm.MenuItems.Add("Green", eh);
cm.MenuItems.Add("White", eh);
foreach (MenuItem mi in cm.MenuItems)
mi.RadioCheck = true;
miColor = cm.MenuItems[3];
miColor.Checked = true;
BackColor = Color.FromName(miColor.Text);
ContextMenu = cm;
}
void MenuColorOnClick(object obj, EventArgs ea)
{
miColor.Checked = false;
miColor = (MenuItem) obj;
miColor.Checked = true;
BackColor = Color.FromName(miColor.Text);
}
}