在.NET应用程序中创建右键单击对话框

时间:2013-02-13 16:08:05

标签: c# dialog right-click

我想在我的.NET应用程序中创建一个类似于Microsoft Word中的“添加到词典”选项的函数。我基本上想在文本框中突出显示一个单词,右键单击它,并选择“添加到自定义词典”。这可能吗?我无法弄清楚如何在右键单击时显示自定义菜单。

2 个答案:

答案 0 :(得分:2)

如果我理解你的话,您可以使用上下文菜单并将其绑定到您的控件。

ContextMenu myContextMenu = new ContextMenu();
// Set various options for the context menu

myControl.ContextMenu = myContextMenu;

答案 1 :(得分:0)

所以答案很简单。我没有意识到Visual Studio工具箱中有一个ContextMenu项。所以我只是做了以下事情:

1) Drag the contextMenu onto the WinForm
2) Assign the contextMenu to the textBox in question
3) Add items to the contextMenu.
4) Assign shortcut keys to each item in the contextMenu.

我仍在尝试弄清楚如何在contextMenu中触发各个项目。