当前位置: 首页>>代码示例>>C#>>正文


C# ContextMenuStrip.Dispose方法代码示例

本文整理汇总了C#中System.Windows.Forms.ContextMenuStrip.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenuStrip.Dispose方法的具体用法?C# ContextMenuStrip.Dispose怎么用?C# ContextMenuStrip.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ContextMenuStrip的用法示例。


在下文中一共展示了ContextMenuStrip.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowContextMenu

        //コンテキストメニュー表示
        public void ShowContextMenu(IPoderosaMenuGroup[] menus, ICommandTarget target, Point point_screen, ContextMenuFlags flags) {
            //まずソート
            ICollection sorted = PositionDesignationSorter.SortItems(menus);
            ContextMenuStrip cm = new ContextMenuStrip();
            MenuUtil.BuildContextMenu(cm, new ConvertingEnumerable<IPoderosaMenuGroup>(sorted), target);
            if (cm.Items.Count == 0) {
                cm.Dispose();
                return;
            }

            //キーボード操作をトリガにメニューを出すときは、選択があったほうが何かと操作しやすい。
            if ((flags & ContextMenuFlags.SelectFirstItem) != ContextMenuFlags.None)
                cm.Items[0].Select();

            // ContextMenuStrip is not disposed automatically and
            // its instance sits in memory till application end.
            // To release a document object related with some menu items,
            // we need to dispose ContextMenuStrip explicitly soon after it disappeared.
            cm.VisibleChanged += new EventHandler(ContextMenuStripVisibleChanged);

            try {
                cm.Show(this, this.PointToClient(point_screen));
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
            }
        }
开发者ID:FNKGino,项目名称:poderosa,代码行数:28,代码来源:PoderosaForm.cs

示例2: CreateCodesMenu

        public static ContextMenuStrip CreateCodesMenu(TextBox tb, params ReplacementVariables[] ignoreList)
        {
            ContextMenuStrip cms = new ContextMenuStrip
            {
                Font = new XmlFont("Lucida Console", 8),
                AutoClose = false,
                Opacity = 0.9,
                ShowImageMargin = false
            };

            var variables = Enum.GetValues(typeof(ReplacementVariables)).Cast<ReplacementVariables>().Where(x => !ignoreList.Contains(x)).
                Select(x => new
                {
                    Name = ReplacementExtension.Prefix + Enum.GetName(typeof(ReplacementVariables), x),
                    Description = x.GetDescription(),
                    Enum = x
                });

            foreach (var variable in variables)
            {
                ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = string.Format("{0} - {1}", variable.Name, variable.Description), Tag = variable.Name };
                tsmi.Click += (sender, e) =>
                {
                    string text = ((ToolStripMenuItem)sender).Tag.ToString();
                    tb.AppendTextToSelection(text);
                };
                cms.Items.Add(tsmi);
            }

            cms.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiClose = new ToolStripMenuItem("Close");
            tsmiClose.Click += (sender, e) => cms.Close();
            cms.Items.Add(tsmiClose);

            tb.MouseDown += (sender, e) =>
            {
                if (cms.Items.Count > 0) cms.Show(tb, new Point(tb.Width + 1, 0));
            };

            tb.Leave += (sender, e) =>
            {
                if (cms.Visible) cms.Close();
            };

            tb.KeyDown += (sender, e) =>
            {
                if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && cms.Visible)
                {
                    cms.Close();
                    e.SuppressKeyPress = true;
                }
            };

            tb.Disposed += (sender, e) => cms.Dispose();

            return cms;
        }
开发者ID:jesse-gao,项目名称:ShareX,代码行数:58,代码来源:NameParser.cs

示例3: ShowMenuAtCursor

		/// <summary>
		/// This method will show the supplied context menu at the mouse cursor, also makes sure it has focus and it's not visible in the taskbar.
		/// </summary>
		/// <param name="menu"></param>
		private static void ShowMenuAtCursor(ContextMenuStrip menu) {
			// find a suitable location
			Point location = Cursor.Position;
			Rectangle menuRectangle = new Rectangle(location, menu.Size);

			menuRectangle.Intersect(WindowCapture.GetScreenBounds());
			if (menuRectangle.Height < menu.Height) {
				location.Offset(-40, -(menuRectangle.Height - menu.Height));
			} else {
				location.Offset(-40, -10);
			}
			// This prevents the problem that the context menu shows in the task-bar
			User32.SetForegroundWindow(PluginUtils.Host.NotifyIcon.ContextMenuStrip.Handle);
			menu.Show(location);
			menu.Focus();

			// Wait for the menu to close, so we can dispose it.
			while (true) {
				if (menu.Visible) {
					Application.DoEvents();
					Thread.Sleep(100);
				} else {
					menu.Dispose();
					break;
				}
			}
		}
开发者ID:logtcn,项目名称:greenshot,代码行数:31,代码来源:AbstractDestination.cs

示例4: InitTrayIcon

        private void InitTrayIcon()
        {
            ContextMenuStrip menu = new ContextMenuStrip();
            menu.Items.AddRange(new ToolStripItem[]
            {
                new ToolStripMenuItem("Show log", null, (q, w) => Process.Start(Settings.LogFile)),
                new ToolStripMenuItem("Clear log", null, (q, w) => File.Delete(Settings.LogFile)),
                new ToolStripMenuItem("Open app location", null, (q, w) => Process.Start(Path.GetDirectoryName(Application.ExecutablePath))),
                new ToolStripMenuItem("Exit", null, (q, w) => Application.Exit())
            });

            _icon = new NotifyIcon()
            {
                Icon = Properties.Resources.synchronize,
                Text = AppName,
                ContextMenuStrip = menu,
                Visible = true
            };
            _icon.MouseClick += (obj, args) =>
            {
                if (args.Button == MouseButtons.Left)
                    Process.Start(Settings.LogFile);
            };

            Application.ApplicationExit += (obj, args) =>
            {
                _icon.Dispose();
                menu.Dispose();
            };
        }
开发者ID:poma,项目名称:remote-server,代码行数:30,代码来源:Program.cs

示例5: Main

        public static void Main()
        {
            var iconPath = Path.Combine(Application.StartupPath, "csFiler.ico");
            using (var icon = new Icon(iconPath))
            using (var commandMenu = new ToolStripMenuItem("コマンド入力"))
            using (var exitMenuItem = new ToolStripMenuItem("終了"))
            using (var contextMenu = new ContextMenuStrip())
            using (var taskTray = new NotifyIcon())
            using (var hotKeyLoop = new HotKeyMessageLoop())
            {
                taskTray.Icon = icon;
                taskTray.Text = "csFiler";
                taskTray.ContextMenuStrip = contextMenu;

                var openCommand = new HotKey(
                    new Action(() =>
                        {
                            var window = new FilerWindow();
                            window.WindowStartupLocation = Wpf.WindowStartupLocation.CenterScreen;
                            window.Show();
                        }),
                    Key.V, ModifierKeys.Windows);

                hotKeyLoop.Add(openCommand);

                contextMenu.Items.AddRange(
                    new ToolStripItem []
                    {
                        commandMenu,
                        exitMenuItem,
                    });
                contextMenu.Click += (sender, e) => openCommand.Action.Invoke();
                exitMenuItem.Click += (sender, e) => Wpf.Application.Current.Shutdown();

                var application = new Wpf.Application()
                {
                    ShutdownMode = Wpf.ShutdownMode.OnExplicitShutdown,
                };

                application.DispatcherUnhandledException += (sender, e) =>
                {
                    MessageBox.Show(
                        string.Concat("想定外のエラーが発生しました。",
                        Environment.NewLine, e.Exception.Message), "csFiler");
                    e.Handled = true;
                };

                application.Exit += (sender, e) =>
                {
                    hotKeyLoop.Dispose();
                    taskTray.Dispose();
                    contextMenu.Dispose();
                    exitMenuItem.Dispose();
                    commandMenu.Dispose();
                    icon.Dispose();
                };

                taskTray.Visible = true;
                application.Run();
            }
        }
开发者ID:setanamimoi,项目名称:csFiler,代码行数:61,代码来源:Program.cs

示例6: WebKit_ShowContextMenu

        private void WebKit_ShowContextMenu(Window window, ContextMenuEventArgs args)
        {
            var menu = new ContextMenuStrip();

            if (!string.IsNullOrEmpty(args.LinkUrl)) {
                menu.Items.Add("&Open Link", null,
                    (s, e) => Window.NavigateTo(args.LinkUrl)
                );
                menu.Items.Add("Copy Link Address", null,
                    (s, e) => {
                        Clipboard.Clear(); Clipboard.SetText(args.LinkUrl);
                    }
                );
                menu.Items.Add("-");
            }

            if (args.IsEditable || !string.IsNullOrEmpty(args.SelectedText)) {
                menu.Items.Add(
                    "&Undo", null,
                    (s, e) => Window.Undo()
                ).Enabled = (args.EditFlags & EditFlags.CanUndo) == EditFlags.CanUndo;
                menu.Items.Add(
                    "&Redo", null,
                    (s, e) => Window.Redo()
                ).Enabled = (args.EditFlags & EditFlags.CanRedo) == EditFlags.CanRedo;

                menu.Items.Add("-");

                menu.Items.Add(
                    "Cu&t", null,
                    (s, e) => Window.Cut()
                ).Enabled = (args.EditFlags & EditFlags.CanCut) == EditFlags.CanCut;
                menu.Items.Add(
                    "&Copy", null,
                    (s, e) => Window.Copy()
                ).Enabled = (args.EditFlags & EditFlags.CanCopy) == EditFlags.CanCopy;
                menu.Items.Add(
                    "&Paste", null,
                    (s, e) => Window.Paste()
                ).Enabled = (args.EditFlags & EditFlags.CanPaste) == EditFlags.CanPaste;
                menu.Items.Add(
                    "&Delete", null,
                    (s, e) => Window.DeleteSelection()
                ).Enabled = (args.EditFlags & EditFlags.CanDelete) == EditFlags.CanDelete;
            } else {
                menu.Items.Add("&Back", null,
                    (s, e) => Window.GoBack()
                ).Enabled = Window.CanGoBack;
                menu.Items.Add("&Forward", null,
                    (s, e) => Window.GoForward()
                ).Enabled = Window.CanGoForward;
                menu.Items.Add("&Reload", null,
                    (s, e) => Window.Refresh()
                ).Enabled = !IsLoading;
                menu.Items.Add("&Stop", null,
                    (s, e) => Window.Stop()
                ).Enabled = IsLoading;
            }

            menu.Items.Add("-");

            menu.Items.Add(
                "Select &All", null,
                (s, e) => Window.SelectAll()
            ).Enabled = (args.EditFlags & EditFlags.CanSelectAll) == EditFlags.CanSelectAll;

            switch (args.MediaType) {
                case MediaType.Image:
                    menu.Items.Add("-");
                    menu.Items.Add(
                        "Copy Image URL", null,
                        (s, e) => Clipboard.SetText(args.SrcUrl)
                    );
                    break;
                default:
                    break;
            }

            menu.Items.Add("-");
            menu.Items.Add("View Page Source", null,
                (s, e) => Window.NavigateTo("viewsource:" + args.PageUrl)
            );

            menu.Closed += (s, e) =>
                this.BeginInvoke((Action)(() => menu.Dispose()));
            menu.Show(this, args.MouseX, args.MouseY);
        }
开发者ID:pathorn,项目名称:berkelium-sharp,代码行数:87,代码来源:WebKitFrame.cs

示例7: tvMyQueries_MouseDown

 private void tvMyQueries_MouseDown(object sender, MouseEventArgs e)
 {
     EventHandler onClick = null;
     if (e.Button == MouseButtons.Right)
     {
         EventHandler handler2 = null;
         TreeNode node = this.tvMyQueries.GetNodeAt(e.Location);
         ContextMenuStrip m = new ContextMenuStrip();
         TreeNode oldNode = this.tvMyQueries.SelectedNode;
         if (node != null)
         {
             this._treeViewQuerySelectSuspended = true;
             this.tvMyQueries.SelectedNode = node;
             this._treeViewQuerySelectSuspended = false;
             if (node is MyQueries.FileNode)
             {
                 if (handler2 == null)
                 {
                     handler2 = (sender, e) => this.tvMyQueries_NodeMouseDoubleClick(sender, new TreeNodeMouseClickEventArgs(node, e.Button, e.Clicks, e.X, e.Y));
                 }
                 m.Items.Add("Open in new tab (middle-click)", Resources.Copy, handler2);
             }
         }
         if (onClick == null)
         {
             onClick = (sender, e) => this.tvMyQueries.RefreshTree();
         }
         m.Items.Add("Refresh tree", Resources.Refresh, onClick);
         m.Closing += delegate (object sender, ToolStripDropDownClosingEventArgs e) {
             if (e.CloseReason != ToolStripDropDownCloseReason.ItemClicked)
             {
                 this.tvMyQueries.SelectedNode = oldNode;
             }
         };
         m.ItemClicked += (sender, e) => m.Dispose();
         m.Show(this.tvMyQueries, e.Location);
     }
     else if (e.Button == MouseButtons.Middle)
     {
         TreeNode nodeAt = this.tvMyQueries.GetNodeAt(e.Location);
         if ((nodeAt != null) && (nodeAt is MyQueries.FileNode))
         {
             this.tvMyQueries_NodeMouseDoubleClick(sender, new TreeNodeMouseClickEventArgs(nodeAt, e.Button, e.Clicks, e.X, e.Y));
         }
     }
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:46,代码来源:MainForm.cs


注:本文中的System.Windows.Forms.ContextMenuStrip.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。