Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
コード例 #1
0
ファイル: PoderosaForm.cs プロジェクト: FNKGino/poderosa
        //コンテキストメニュー表示
        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);
            }
        }
コード例 #2
0
        public override void CloseTabPage()
        {
            if (Dirty)
            {
                if (DialogResult.Yes == MessageBox.Show("Do you want to save?", "Save", MessageBoxButtons.YesNoCancel))
                {
                    SaveTabPage();
                }
            }

            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();
            GC.Collect();

            panelTabPage.Dispose();
            //components.Dispose();
            //dataGridView1.Dispose();
            foreach (Control control in this.Controls)
            {
                control.Dispose();
            }

            contextMenuStrip1.Dispose();
            deleteToolStripMenuItem.Dispose();
            addToolStripMenuItem.Dispose();
            copyToolStripMenuItem.Dispose();
            pasteToolStripMenuItem.Dispose();
            dataGridView1.Dispose();
            this.Controls.Clear();
        }
コード例 #3
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             contextMenuStrip.Dispose();
             notifyIcon.Dispose();
             if (watcher != null)
             {
                 watcher.Dispose();
             }
         }
     }
     disposed = true;
 }
コード例 #4
0
        public override void CloseTabPage()
        {
            base.CloseTabPage();

            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();
            GC.Collect();

            panelTabPage.Dispose();
            //components.Dispose();
            //dataGridView1.Dispose();
            foreach (Control control in this.Controls)
            {
                control.Dispose();
            }

            contextMenuStrip1.Dispose();
            deleteToolStripMenuItem.Dispose();
            addToolStripMenuItem.Dispose();
            copyToolStripMenuItem.Dispose();
            pasteToolStripMenuItem.Dispose();
            dataGridView1.Dispose();
            this.Controls.Clear();
        }
コード例 #5
0
ファイル: NameParser.cs プロジェクト: jesse-gao/ShareX
        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;
        }
コード例 #6
0
		/// <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;
				}
			}
		}
コード例 #7
0
ファイル: Program.cs プロジェクト: poma/remote-server
        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();
            };
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: setanamimoi/csFiler
        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();
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: CuneytKukrer/TestProject
 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));
         }
     }
 }