Mnemonic not showing on a System.Windows.Forms.ContextMenu

删除回忆录丶 提交于 2019-12-12 10:29:42

问题


I'm having some problems with Mnemonics and ContextMenus - although the Mnemonic property of the Menutem is set correctly the little underline wont show under the relevant key. Here is my code:

private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    System.Windows.Forms.ContextMenu menu = new ContextMenu();
    menu.MenuItems.Add("Hello &World");
    menu.Show(this, e.Location);
}

What am I doing wrong?


回答1:


There is a windows setting to "Hide underlined letters for keyboard navigation until I press the ALT key." It is under Display Properties --> Appearance --> Effects on XP ... Could that be what you're seeing?




回答2:


Your code should work. Try using different text for your menu item. e.g "&Hello" or "&World". Also try setting the ShowShortcut to true, though .NET should do it for you by default.

menu.MenuItems[0].ShowShortcut = true;


来源:https://stackoverflow.com/questions/1520126/mnemonic-not-showing-on-a-system-windows-forms-contextmenu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!