0

有一个奇怪的。

我有一个包含 ContextMenuStrip 的类,当在其上调用 .Show 时,什么也没有发生。正如您在下面看到的那样,我尝试写入日志文件,并且第一行被击中,但是一旦它击中我尝试显示它的行,程序似乎就像遇到了返回一样。

这是课程:

class AnywhereMenu
{
    frmMain parent;
    KeyboardHook hook = new KeyboardHook();
    ContextMenuStrip anymenu = new ContextMenuStrip();

    public AnywhereMenu(frmMain _parent)
    {
        parent = _parent;
        populateContextMenu();
    }

    void populateContextMenu()
    {
        ToolStripMenuItem mnuTasks = new ToolStripMenuItem();
        ToolStripMenuItem mnuComments = new ToolStripMenuItem();
        ToolStripMenuItem mnuTools = new ToolStripMenuItem();

        mnuTasks.Text = "&Tasks";
        mnuTasks.DropDownItems.Add("Item1", null, new EventHandler(TaskHandler));
        mnuTasks.DropDownItems.Add("Item2", null, new EventHandler(TaskHandler));

        mnuComments.Text = "&Comments";
        mnuComments.DropDownItems.Add("Item1", null, new EventHandler(CommentHandler));
        mnuComments.DropDownItems.Add("Item2", null, new EventHandler(CommentHandler));
        mnuComments.DropDownItems.Add("Item3", null, new EventHandler(CommentHandler));

        mnuTools.Text = "Links//Tools";
        mnuTools.DropDownItems.Add("Item1", null, new EventHandler(ToolHandler));
        mnuTools.DropDownItems.Add("Item2", null, new EventHandler(ToolHandler));
        mnuTools.DropDownItems.Add("Item3", null, new EventHandler(ToolHandler));

        anymenu.Items.Add(mnuTasks);
        anymenu.Items.Add(mnuComments);
        anymenu.Items.Add(mnuTools);
    }

    public void MenuShow()
    {
        Settings.Save.debugLog("Displaying context menu!");
        anymenu.Show(Cursor.Position);
        return;
    }
}

以及调用它的代码:

if (keyChar == "Space")
{
    Settings.Save.debugLog("Entered Context Menu Block");
    anyMenu.MenuShow();
    Settings.Save.debugLog("Exiting Context Menu Block");
}

现在,调试日志将显示以下行: Entered Context Menu Block,但既不显示“正在显示上下文菜单!” 或“退出上下文菜单块”被击中。有任何想法吗?谢谢 :-)

编辑 - 我忘了补充说它在我开发它的机器上运行良好,但任何其他计算机都会出现上述行为。不知道这里发生了什么:-(

4

0 回答 0