Example #1
0
        int OnMouseLLHook(int code, WM message, IntPtr state)
        {
            try
            {
                if (message == WM.LBUTTONDOWN)
                {
                    var clientPos = virtualContextMenu.PointToClient(Cursor.Position);
                    if (virtualContextMenu.Visible && virtualContextMenu.ClientRectangle.Contains(clientPos) == false)
                    {
                        virtualContextMenu.Hide();
                    }
                }
                if (message == WM.RBUTTONUP)
                {
                    // コンテキストメニューを表示
                    virtualContextMenu.Items.Clear();

                    for (int i = 0; i < appGraph.edges.Count; i++)
                    {
                        AppEdge appEdge = appGraph.edges[i];
                        if (!IsValidEdge(appEdge, TriggerType.ContextMenu))
                        {
                            continue;
                        }
                        var item = new ToolStripMenuItem(appEdge.ActionHandler.ContextMenuText);
                        item.Click += (s, ee) => ExecuteActionHandler(appEdge);
                        item.Invalidate();
                        virtualContextMenu.Items.Add(item);
                    }

                    if (virtualContextMenu.Items.Count >= 1)
                    {
                        ToolStripMenuItem[] itemList = new ToolStripMenuItem[virtualContextMenu.Items.Count];
                        for (int j = 0; j < virtualContextMenu.Items.Count; j++)
                        {
                            itemList[j] = virtualContextMenu.Items[j] as ToolStripMenuItem;
                        }
                        virtualContextMenu.Show(new Point(Cursor.Position.X, Cursor.Position.Y - 22 * virtualContextMenu.Items.Count));
                    }
                }
                return(CallNextHookEx(mouseHook, code, message, state));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(CallNextHookEx(mouseHook, code, message, state));
            }
        }
Example #2
0
        private void CreateShortcutContextMenu()
        {
            RestoreShortcut();
            _contextMenuShortcuts          = new ContextMenuStrip();
            _contextMenuShortcuts.Opening += (sender, args) =>
            {
                _contextMenuShortcuts.Items.Clear();
                _contextMenuShortcuts.Items.Add("Explorer", null, (o, eventArgs) => _explorerCleaner.OpenExplorer(""));
                _contextMenuShortcuts.Items.Add(new ToolStripSeparator());

                var closedExplorers = _explorerCleaner.ClosedExplorers.OrderByDescending(x => x.IsFavorited)
                                      .ThenByDescending(x => x.LastUpdateDateTime).Take(10);

                foreach (var closedExplorer in closedExplorers)
                {
                    var item = new ToolStripMenuItem(closedExplorer.LocationPath);
                    item.Image  = closedExplorer.IsFavorited ? Resources.favorite : null;
                    item.Click += (o, eventArgs) => _explorerCleaner.OpenExplorer(closedExplorer);
                    _contextMenuShortcuts.Items.Add(item);
                }

                if (_shortcuts.Length > 0)
                {
                    _contextMenuShortcuts.Items.Add(new ToolStripSeparator());
                    foreach (var shortcutItem in _shortcuts)
                    {
                        _contextMenuShortcuts.Items.Add(shortcutItem.Name, null,
                                                        (o, eventArgs) => shortcutItem.Exec());
                    }
                }
                args.Cancel = false;
            };
            _contextMenuShortcuts.Closing += (sender, args) =>
            {
                // 任意のクリックで閉じるが、カーソルがコンテキストメニューにあるときは閉じない(イベントが消えるので)
                if (args.CloseReason == ToolStripDropDownCloseReason.AppFocusChange &&
                    _contextMenuShortcuts.ClientRectangle.Contains(
                        _contextMenuShortcuts.PointToClient(Cursor.Position)))
                {
                    args.Cancel = true;
                }
            };
        }
Example #3
0
        public void PerformClickOnContextMenu()
        {
            EmptyHandler del = delegate()
            {
                Point point = cMS_MatchedGestures.PointToClient(Cursor.Position);
                //Debug.WriteLine(string.Format("PerformClickOnContextMenu X: {0} Y: {1}", point.X, point.Y));
                ToolStripItem item = cMS_MatchedGestures.GetItemAt(point);

                if (item == null)
                {
                    point.Y -= 1;

                    foreach (ContextMenuStrip contextMenu in m_cmsList)
                    {
                        point = contextMenu.PointToClient(Cursor.Position);
                        item  = contextMenu.GetItemAt(point);
                        if (item != null)
                        {
                            break;
                        }
                    }
                }

                if (item != null)
                {
                    ToolStripMenuItem menuItem = (ToolStripMenuItem)item;
                    if (menuItem.DropDownItems.Count == 0)
                    {
                        item.PerformClick();
                    }
                }
            };

            if (this.InvokeRequired)
            {
                this.Invoke(del);
            }
            else
            {
                del();
            }
        }
    protected virtual void OnShowContextMenu(ShowContextMenuEventArgs e)
    {
        var handler = ShowContextMenu;

        if (handler != null)
        {
            handler(e);
            if (e.ContextMenuToShow != null)
            {
                ContextMenuStrip toolStrip = (ContextMenuStrip)Control.FromHandle(Handle);
                Point            client    = toolStrip.PointToClient(Control.MousePosition);
                SourceItem                  = toolStrip.GetItemAt(client);
                previousItemBackColor       = SourceItem.BackColor;
                SourceItem.BackColor        = SystemColors.MenuHighlight;
                e.ContextMenuToShow.Closed -= restoreItemState;
                e.ContextMenuToShow.Closed += restoreItemState;
                keepOpen = true;
                e.ContextMenuToShow.Show(Control.MousePosition);
                keepOpen = false;
            }
        }
    }
Example #5
0
        private void CreateClipboardContextMenu()
        {
            _contextMenuClipboardHistories          = new ContextMenuStrip();
            _contextMenuClipboardHistories.Opening += (sender, args) =>
            {
                _contextMenuClipboardHistories.Items.Clear();
                var clipboardHistoriesItem = new ToolStripMenuItem("Clipboard Histories");
                clipboardHistoriesItem.Enabled = false;
                _contextMenuClipboardHistories.Items.Add(clipboardHistoriesItem);
                _contextMenuClipboardHistories.Items.Add(new ToolStripSeparator());

                foreach (var c in _clipboardItemQueue.Reverse())
                {
                    var item = new ToolStripMenuItem(c.ToString(), null, (o, eventArgs) =>
                    {
                        Clipboard.SetText(c.GetText());
                        _contextMenuClipboardHistories.Close(ToolStripDropDownCloseReason.ItemClicked);
                        SendCtrlV((IntPtr)_contextMenuClipboardHistories.Tag);
                    });
                    item.ToolTipText = c.GetText();
                    _contextMenuClipboardHistories.Items.Add(item);
                    _contextMenuClipboardHistories.Items.Add(new ToolStripSeparator());
                }
                _contextMenuClipboardHistories.Items.RemoveAt(_contextMenuClipboardHistories.Items.Count - 1);
            };

            _contextMenuClipboardHistories.Closing += (sender, args) =>
            {
                // 任意のクリックで閉じるが、カーソルがコンテキストメニューにあるときは閉じない(イベントが消えるので)
                if (args.CloseReason == ToolStripDropDownCloseReason.AppFocusChange &&
                    _contextMenuClipboardHistories.ClientRectangle.Contains(
                        _contextMenuClipboardHistories.PointToClient(Cursor.Position)))
                {
                    args.Cancel = true;
                }
            };
        }