本文整理匯總了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);
}
}