本文整理汇总了C#中System.Windows.Forms.ContextMenuStrip类的典型用法代码示例。如果您正苦于以下问题:C# ContextMenuStrip类的具体用法?C# ContextMenuStrip怎么用?C# ContextMenuStrip使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContextMenuStrip类属于System.Windows.Forms命名空间,在下文中一共展示了ContextMenuStrip类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildCyberwareTree
/// <summary>
/// Build up the Tree for the current piece of Cyberware and all of its children.
/// </summary>
/// <param name="objCyberware">Cyberware to iterate through.</param>
/// <param name="objParentNode">TreeNode to append to.</param>
/// <param name="objMenu">ContextMenuStrip that the new Cyberware TreeNodes should use.</param>
/// <param name="objGearMenu">ContextMenuStrip that the new Gear TreeNodes should use.</param>
public void BuildCyberwareTree(Cyberware objCyberware, TreeNode objParentNode, ContextMenuStrip objMenu, ContextMenuStrip objGearMenu)
{
TreeNode objNode = new TreeNode();
objNode.Text = objCyberware.DisplayName;
objNode.Tag = objCyberware.InternalId;
if (objCyberware.Notes != string.Empty)
objNode.ForeColor = Color.SaddleBrown;
objNode.ToolTipText = objCyberware.Notes;
objNode.ContextMenuStrip = objMenu;
objParentNode.Nodes.Add(objNode);
objParentNode.Expand();
foreach (Cyberware objChild in objCyberware.Children)
BuildCyberwareTree(objChild, objNode, objMenu, objGearMenu);
foreach (Gear objGear in objCyberware.Gear)
{
TreeNode objGearNode = new TreeNode();
objGearNode.Text = objGear.DisplayName;
objGearNode.Tag = objGear.InternalId;
if (objGear.Notes != string.Empty)
objGearNode.ForeColor = Color.SaddleBrown;
objGearNode.ToolTipText = objGear.Notes;
objGearNode.ContextMenuStrip = objGearMenu;
BuildGearTree(objGear, objGearNode, objGearMenu);
objNode.Nodes.Add(objGearNode);
objNode.Expand();
}
}
示例2: InitializeTrayIconAndProperties
public void InitializeTrayIconAndProperties()
{
serviceStatus = _serviceManager.GetServiceStatus();
//Set the Tray icon
if (serviceStatus == ServiceControllerStatus.Running)
notifyTrayIcon.Icon = Properties.Resources.TrayIconRunning;
else if (serviceStatus == ServiceControllerStatus.Stopped)
notifyTrayIcon.Icon = Properties.Resources.TrayIconStopped;
else
notifyTrayIcon.Icon = Properties.Resources.TrayIconActive;
//Setup context menu options
trayContextMenu = new ContextMenuStrip();
trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = ActionConstants.REFRESH, Text = "Refresh Status" });
trayContextMenu.Items.Add("-");
_startServiceItem = new ToolStripMenuItem() { Enabled = ServiceControllerStatus.Stopped.Equals(serviceStatus), Name = ActionConstants.START_SERVICE, Text = "Start Service" };
trayContextMenu.Items.Add(_startServiceItem);
_stopServiceItem = new ToolStripMenuItem() { Enabled = ServiceControllerStatus.Running.Equals(serviceStatus), Name = ActionConstants.STOP_SERVICE, Text = "Stop Service" };
trayContextMenu.Items.Add(_stopServiceItem);
trayContextMenu.Items.Add("-");
trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = ActionConstants.SHOW_LOGS, Text = "Show Logs" });
trayContextMenu.Items.Add("-");
trayContextMenu.Items.Add(new ToolStripMenuItem() { Name = "actionExit", Text = "Exit" });
trayContextMenu.ItemClicked += trayContextMenu_ItemClicked;
//Initialize the tray icon here
this.notifyTrayIcon.ContextMenuStrip = trayContextMenu;
}
示例3: MapViewControl
public MapViewControl(frmMain Owner)
{
_Owner = Owner;
InitializeComponent();
ListSelect = new ContextMenuStrip();
ListSelect.ItemClicked += ListSelect_Click;
ListSelect.Closed += ListSelect_Close;
UndoMessageTimer = new Timer();
UndoMessageTimer.Tick += RemoveUndoMessage;
OpenGLControl = Program.OpenGL1;
pnlDraw.Controls.Add(OpenGLControl);
GLInitializeDelayTimer = new Timer();
GLInitializeDelayTimer.Interval = 50;
GLInitializeDelayTimer.Tick += GLInitialize;
GLInitializeDelayTimer.Enabled = true;
tmrDraw = new Timer();
tmrDraw.Tick += tmrDraw_Tick;
tmrDraw.Interval = 1;
tmrDrawDelay = new Timer();
tmrDrawDelay.Tick += tmrDrawDelay_Tick;
tmrDrawDelay.Interval = 30;
UndoMessageTimer.Interval = 4000;
}
示例4: ObedienceContext
internal ObedienceContext()
{
//Instantiate the component Module to hold everything
_components = new System.ComponentModel.Container();
Trace.Listeners.Add(new TextWriterTraceListener("C:\\temp\\Obedience.log"));
//Instantiate the NotifyIcon attaching it to the components container and
//provide it an icon, note, you can imbed this resource
_notifyIcon = new NotifyIcon(_components);
_notifyIcon.Icon = Resources.AppIcon;
_notifyIcon.Text = "Obedience";
_notifyIcon.Visible = true;
//Instantiate the context menu and items
var contextMenu = new ContextMenuStrip();
var displayForm = new ToolStripMenuItem();
var exitApplication = new ToolStripMenuItem();
//Attach the menu to the notify icon
_notifyIcon.ContextMenuStrip = contextMenu;
//Setup the items and add them to the menu strip, adding handlers to be created later
displayForm.Text = "Do something";
displayForm.Click += mDisplayForm_Click;
contextMenu.Items.Add(displayForm);
exitApplication.Text = "Exit";
exitApplication.Click += mExitApplication_Click;
contextMenu.Items.Add(exitApplication);
Trace.WriteLine("Obedience started");
scanner = new AcdController(new IPEndPoint(new IPAddress(new byte[] {10, 0, 3, 220}), 5003));
//scanner.Reboot();
Trace.AutoFlush = true;
scanner.ConnectedChanged += new ConnectedChangedEventHandler(scanner_ConnectedChanged);
}
示例5: SimulationModeItemManager
public SimulationModeItemManager(ContextMenuStrip contextMenuStrip, CarModelGraphicControl graphicControl)
{
model = new CarModel(new CarModelState(new PointD(ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X),
ComMath.Normal(0, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)),
new PointD(0, 1)));
finish = new FinishModel(new PointD(ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_X, CarModelState.MAX_POS_X),
ComMath.Normal(0.5, 0, 1, CarModelState.MIN_POS_Y, CarModelState.MAX_POS_Y)),
0);
obstacles = new List<ObstacleModel>();
dragables = new List<IDragable>();
sampledCarState = model.state;
dragables.Add(model);
dragables.Add(finish);
dragged = null;
state = State.NONE;
this.contextMenuStrip = contextMenuStrip;
this.graphicControl = graphicControl;
contextMenuStrip.Items[0].Click += new EventHandler(newObstacle);
contextMenuStrip.Items[1].Click += new EventHandler(deleteObstacle);
}
示例6: TaskBarIconMenu
public TaskBarIconMenu()
{
TrayIcon_Menu = new ContextMenuStrip();
TrayIcon_Artist = new ToolStripLabel();
TrayIcon_Title = new ToolStripLabel();
TrayIcon_Diff = new ToolStripLabel();
TrayIcon_Play = new ToolStripMenuItem();
TrayIcon_PlayNext = new ToolStripMenuItem();
TrayIcon_PlayPrev = new ToolStripMenuItem();
TrayIcon_Exit = new ToolStripMenuItem();
TrayIcon_Menu.SuspendLayout();
TrayIcon_Menu.Items.AddRange(new ToolStripItem[] {
TrayIcon_Artist,
TrayIcon_Title,
TrayIcon_Diff,
TrayIcon_Play,
TrayIcon_PlayNext,
TrayIcon_PlayPrev,
TrayIcon_Exit});
TrayIcon_Menu.Name = "TrayIcon_Menu";
TrayIcon_Menu.Size = new Size(176, 176);
// TrayIcon_Artist
TrayIcon_Artist.Name = "TrayIcon_Artist";
TrayIcon_Artist.Text = LanguageManager.Get("TrayIcon_Aritst_Text");
TrayIcon_Artist.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Bold, GraphicsUnit.Point, 134);
// TrayIcon_Title
TrayIcon_Title.Name = "TrayIcon_Title";
TrayIcon_Title.Text = LanguageManager.Get("TrayIcon_Title_Text");
TrayIcon_Title.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Bold, GraphicsUnit.Point, 134);
// TrayIcon_Diff
TrayIcon_Diff.Name = "TrayIcon_Diff";
TrayIcon_Diff.Text = LanguageManager.Get("TrayIcon_Diff_Text");
TrayIcon_Diff.Font = new Font("Microsoft YaHei UI", 9F, FontStyle.Bold, GraphicsUnit.Point, 134);
// TrayIcon_Play
TrayIcon_Play.Name = "TrayIcon_Play";
TrayIcon_Play.Text = LanguageManager.Get("TrayIcon_Play_Pause_Text");
TrayIcon_Play.Click += delegate { SendKeys.Send("%{F5}"); };
// TrayIcon_PlayNext
TrayIcon_PlayNext.Name = "TrayIcon_PlayNext";
TrayIcon_PlayNext.Text = LanguageManager.Get("TrayIcon_PlayNext_Text");
TrayIcon_PlayNext.Click += delegate { SendKeys.Send("%{RIGHT}"); };
// TrayIcon_PlayNext
TrayIcon_PlayPrev.Name = "TrayIcon_PlayPrev";
TrayIcon_PlayPrev.Text = LanguageManager.Get("TrayIcon_PlayPrev_Text");
TrayIcon_PlayPrev.Click += delegate { SendKeys.Send("%{LEFT}"); };
// TrayIcon_Exit
TrayIcon_Exit.Name = "TrayIcon_Exit";
TrayIcon_Exit.Text = LanguageManager.Get("TrayIcon_Exit_Text");
TrayIcon_Exit.Click += delegate
{
if (
MessageBox.Show(LanguageManager.Get("Comfirm_Exit_Text"), LanguageManager.Get("Tip_Text"),
MessageBoxButtons.YesNo) != DialogResult.Yes) return;
Core.MainIsVisible = false;
Core.Exit();
Environment.Exit(0);
};
TrayIcon_Menu.ResumeLayout(false);
}
示例7: Clone
// minimal Clone implementation for DGV support only.
internal ContextMenuStrip Clone() {
// VERY limited support for cloning.
ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
// copy over events
contextMenuStrip.Events.AddHandlers(this.Events);
contextMenuStrip.AutoClose = AutoClose;
contextMenuStrip.AutoSize = AutoSize;
contextMenuStrip.Bounds = Bounds;
contextMenuStrip.ImageList = ImageList;
contextMenuStrip.ShowCheckMargin = ShowCheckMargin;
contextMenuStrip.ShowImageMargin = ShowImageMargin;
// copy over relevant properties
for (int i = 0; i < Items.Count; i++) {
ToolStripItem item = Items[i];
if (item is ToolStripSeparator) {
contextMenuStrip.Items.Add(new ToolStripSeparator());
}
else if (item is ToolStripMenuItem) {
ToolStripMenuItem menuItem = item as ToolStripMenuItem;
contextMenuStrip.Items.Add(menuItem.Clone());
}
}
return contextMenuStrip;
}
示例8: ListGroup
public ListGroup()
: base()
{
defaultContextMenuStrip = new ContextMenuStrip();
defaultContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(regularListViewMenu_Opening);
this.ContextMenuStrip = defaultContextMenuStrip;
_Columns = new ListGroupColumnCollection(this);
_Items = new ListGroupItemCollection(this);
// The Imagelist is used to hold images for the expanded and contracted icons in the
// Left-most columnheader:
this.SmallImageList = new ImageList();
// The tilting arrow images are available in the app resources:
this.SmallImageList.Images.Add(COLLAPSED_IMAGE_KEY, Properties.Resources.CollapsedGroupSmall_png_1616);
this.SmallImageList.Images.Add(EXPANDED_IMAGE_KEY, Properties.Resources.ExpandedGroupSmall_png_1616);
this.SmallImageList.Images.Add(EMPTY_IMAGE_KEY, Properties.Resources.EmptyGroupSmall_png_1616);
// The stateImageList is used as a hack method to allow larger Row Heights:
this.StateImageList = new ImageList();
// Default configuration (for this sample. Obviously, configure to fit your needs:
this.View = System.Windows.Forms.View.Details;
this.FullRowSelect = true;
this.GridLines = true;
this.LabelEdit = false;
this.Margin = new Padding(0);
this.SetAutoSizeMode(AutoSizeMode.GrowAndShrink);
this.MaximumSize = new System.Drawing.Size(1000, 300);
// Subscribe to local Events:
this.ColumnClick += new ColumnClickEventHandler(ListGroup_ColumnClick);
}
示例9: Create
/// <summary>
/// Creates this instance.
/// </summary>
/// <returns>ContextMenuStrip</returns>
public ContextMenuStrip Create()
{
// Add the default menu options.
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem item;
ToolStripSeparator sep;
this._textmodeItem = new ToolStripMenuItem();
this._textmodeItem.Text = "Text mode";
this._textmodeItem.Enabled = false;
menu.Items.Add(this._textmodeItem);
this.SetTextModeText(BopomofoRegistry.IsSimplifiedEnable(), false);
// About.
item = new ToolStripMenuItem();
item.Text = "About";
item.Click += new EventHandler(this.About_Click);
menu.Items.Add(item);
// Separator.
sep = new ToolStripSeparator();
menu.Items.Add(sep);
// Exit.
item = new ToolStripMenuItem();
item.Text = "Exit";
item.Click += new System.EventHandler(this.Exit_Click);
menu.Items.Add(item);
return menu;
}
示例10: SysTrayContext
public SysTrayContext()
{
container = new System.ComponentModel.Container();
notifyIcon = new NotifyIcon(this.container);
notifyIcon.Icon = forever.icon;
notifyIcon.Text = "Forever";
notifyIcon.Visible = true;
//Instantiate the context menu and items
contextMenu = new ContextMenuStrip();
menuItemExit = new ToolStripMenuItem();
//Attach the menu to the notify icon
notifyIcon.ContextMenuStrip = contextMenu;
menuItemExit.Text = "Exit";
menuItemExit.Click += new EventHandler(menuItemExit_Click);
contextMenu.Items.Add(menuItemExit);
timer = new Timer(this.container);
timer.Interval = 1000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
示例11: NotifyIconHelper
/// <summary>
/// 构造 NotifyIconHelper 的新实例。
/// </summary>
/// <param name="mainForm">应用程序主窗体。</param>
/// <param name="notHandleClosingEvent">是否不让 NotifyIconHelper 处理主窗体的 FormClosing 事件。
/// <remarks>
/// 缺省情况下此参数应为 False,即 NotifyIconHelper 总是通过处理主窗体的 FormClosing 事件达到让主窗体在关闭后
/// 驻留系统托盘区的目的。但特殊情况下,应用程序可能会自己处理主窗体的的 FormClosing 事件,此时应设置此属性为 True。
/// </remarks>
/// </param>
/// <param name="showPromptWhenClosing">是否在窗体关闭时给用户以提示,仅当 NotHandleClosingEvent = False 时有效。</param>
public NotifyIconHelper( Form mainForm, bool notHandleClosingEvent, bool showPromptWhenClosing )
{
_mainForm = mainForm;
_showPromptWhenClosing = showPromptWhenClosing;
_imgLst = new ImageList();
_imgLst.Images.Add( _mainForm.Icon );
Image img = Image.FromHbitmap( _mainForm.Icon.ToBitmap().GetHbitmap() );
_contextMenu = new ContextMenuStrip();
_contextMenu.Items.Add( new ToolStripMenuItem( Resources.MenuShowMainForm, img, OnShowMainForm ) );
_contextMenu.Items.Add( new ToolStripSeparator() );
_contextMenu.Items.Add( new ToolStripMenuItem( Resources.MenuExit, null, OnExitApp ) );
_notifyIcon = new NotifyIcon();
_notifyIcon.Icon = GetAppIcon();
_notifyIcon.Text = _mainForm.Text;
_notifyIcon.Visible = true;
_notifyIcon.ContextMenuStrip = _contextMenu;
_notifyIcon.MouseDown += _notifyIcon_MouseDown;
_mainForm.FormClosed += _mainForm_FormClosed;
if( notHandleClosingEvent == false )
_mainForm.FormClosing += new FormClosingEventHandler( _mainForm_FormClosing );
}
示例12: Create
public ContextMenuStrip Create()
{
// Add the default menu options.
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem item;
ToolStripSeparator sep;
// Name
item = new ToolStripMenuItem();
item.Text = "SimplePTT 1.1";
item.Enabled = false;
menu.Items.Add(item);
// Separator
sep = new ToolStripSeparator();
menu.Items.Add(sep);
// Exit
item = new ToolStripMenuItem();
item.Text = "Exit";
item.Click += new System.EventHandler(Exit_Click);
menu.Items.Add(item);
return menu;
}
示例13: CreateMenu
protected override ContextMenuStrip CreateMenu() {
var client = Novaroma.Helper.CreateShellServiceClient();
Helper.SetCulture(client);
var path = SelectedItemPaths.First();
var menu = new ContextMenuStrip();
var menuRoot = new ToolStripMenuItem {
Text = Constants.Novaroma,
Image = Resources.Img_Logo_16x16
};
var downloadable = client.GetDownloadable(path).Result;
if (downloadable != null) {
var updateWatchStatus = new ToolStripMenuItem {
Text = Resources.IsWatched,
Image = Resources.Img_Watch_16x16,
Checked = downloadable.IsWatched
};
updateWatchStatus.Click += (sender, args) => UpdateWatchStatus(path, !downloadable.IsWatched);
menuRoot.DropDownItems.Add(updateWatchStatus);
}
var downloadSubtitle = new ToolStripMenuItem {
Text = Resources.DownloadSubtitle,
Image = Resources.Img_DownloadSubtitle_16x16
};
downloadSubtitle.Click += (sender, args) => DownloadSubtitle(path);
menuRoot.DropDownItems.Add(downloadSubtitle);
menu.Items.Add(menuRoot);
return menu;
}
示例14: Read
/// <summary>
/// Read a streams file adding submenus and items to a context menu.
/// </summary>
/// <param name="filepath">Path to the streams file to read lines from.</param>
/// <param name="menu">Target context menu.</param>
/// <param name="onClick">Click event to attach to menu items.</param>
public void Read(String filepath, ContextMenuStrip menu, EventHandler onClick)
{
this.filepath = filepath;
this.menu = menu;
this.onClick = onClick;
try
{
// start at the menu root:
currentMenuItemCollection = menu.Items;
foreach (String line in File.ReadLines(filepath))
{
currentLineNumber++;
currentLine = line;
ReadLine(line);
}
// add pending items for the last submenu:
AddCurrentMenuItems();
}
finally
{
ResetState();
}
}
示例15: CreateContextMenu
public static ContextMenuStrip CreateContextMenu(object owner, string addInTreePath)
{
if (addInTreePath == null) {
return null;
}
try {
ArrayList buildItems = AddInTree.GetTreeNode(addInTreePath).BuildChildItems(owner);
ContextMenuStrip contextMenu = new ContextMenuStrip();
contextMenu.Items.Add(new ToolStripMenuItem("dummy"));
contextMenu.Opening += delegate {
contextMenu.Items.Clear();
foreach (object item in buildItems) {
if (item is ToolStripItem) {
contextMenu.Items.Add((ToolStripItem)item);
} else {
ISubmenuBuilder submenuBuilder = (ISubmenuBuilder)item;
contextMenu.Items.AddRange(submenuBuilder.BuildSubmenu(null, owner));
}
}
};
contextMenu.Opened += ContextMenuOpened;
contextMenu.Closed += ContextMenuClosed;
return contextMenu;
} catch (TreePathNotFoundException) {
MessageService.ShowError("Warning tree path '" + addInTreePath +"' not found.");
return null;
}
}