简体   繁体   English

C#-菜单栏查询

[英]C# - Menu Strip Query

I have two questions regarding the windows form menu strip: 关于Windows窗体菜单栏,我有两个问题:

1. How to force the form to always show the helper keys? 1.如何强制表单始终显示帮助键? Currently the letter underlines are displayed only if the Alt key is pressed. 当前,仅在按下Alt键时显示字母下划线。

2. What is the command to cause a menu to drop down? 2.什么是导致菜单下拉的命令? Usually a menu drops down after the user clicks the menu button or navigates it with the keyboard, but I want to cause a menu to drop down by pressing an interface button and I can't figure out how to do it. 通常,在用户单击菜单按钮或使用键盘对其进行导航之后,菜单会下拉,但是我想通过按下界面按钮来使菜单下拉,但我不知道该怎么做。 I tried fiddling the DropDown property, but it didn't help. 我尝试摆弄DropDown属性,但没有帮助。

  1. AFAIK, it is not easily possible to do that in C#. 据我所知,它是不会轻易可以做到的是,在C#。 The easiest way is to change the Windows settings. 最简单的方法是更改​​Windows设置。 On Windows 7: 在Windows 7上:
    • Go to Control panel 转到控制面板
    • Ease of Access Center 轻松进入中心
    • Make the Keyboard easier to use 使键盘更易于使用
    • Check Underline keyboard shortcuts and access keys . 检查下划线键盘快捷键和访问键
  1. With ToolStripMenuItem there are three properties you need to look at: ShortcutKeyDisplayString ShortcutKeys ShowShortcutKeys 使用ToolStripMenuItem,您需要查看三个属性:ShortcutKeyDisplayString ShortcutKeys ShowShortcutKeys

    • Although the three apply to the root menu item, say File or Help, you will not be able to see the short cuts, however you should be able to enable the ShortcutKeys, set ShowShortcutKeys to true and without modifying ShortcutKeyDisplayStringhave them appear next to sub ToolStripMenuItem's. 尽管这三个适用于根菜单项(例如“文件”或“帮助”),但是您将无法看到快捷方式,但是您应该能够启用ShortcutKeys,将ShowShortcutKeys设置为true,而无需修改ShortcutKeyDisplayString,让它们出现在子ToolStripMenuItem的旁边。 。
  2. The method you are looking for on ToolStripMenuItem is ShowDropDown() , executing this method will drop down the menu. 您在ToolStripMenuItem上寻找的方法是ShowDropDown() ,执行此方法将下拉菜单。

Example: 例:

((ToolStripMenuItem)FileMenu.Items[0]).ShowDropDown();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM