【问题标题】:Underscore in button text property does not show up按钮文本属性中的下划线不显示
【发布时间】:2011-08-19 10:09:13
【问题描述】:

在我的 C# WinForms 程序中,我有一些按钮,并为它们分配了一些快捷方式。快捷方式工作正常,但在用户按下 ALT 键之前,按钮文本属性中的下划线不会显示。如何更改此默认行为?

这是我的下划线

Button1.Text = "&EDIT";

谢谢。

【问题讨论】:

    标签: c# winforms button keyboard-shortcuts


    【解决方案1】:

    我发现这篇文章使用了 P/Invoke:

    http://www.tompuleo.com/2010/05/force-c-to-always-show-keyboard.html

    它解释了如何在每个应用程序的基础上切换此行为。

    来自链接:


    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern int SystemParametersInfo(int uAction, int uParam, int lpvParam, int fuWinIni);
    
    private const int SPI_SETKEYBOARDCUES = 4107; //100B
    private const int SPIF_SENDWININICHANGE = 2;
    
    [STAThread]
    static void Main()
    {
        // always show accelerator underlines
        SystemParametersInfo(SPI_SETKEYBOARDCUES, 0, 1, SPIF_SENDWININICHANGE);
    
        Application.Run(new MainForm());
    }
    

    【讨论】:

      【解决方案2】:

      这是 Windows 的系统范围设置,与您的程序无关。

      【讨论】:

      • +1:虽然从技术上讲不是问题的答案,但它仍然是正确的做法:不要摆弄用户设置。
      猜你喜欢
      • 2013-08-22
      • 2016-03-13
      • 2011-02-08
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      • 2016-04-17
      • 2021-09-15
      • 1970-01-01
      相关资源
      最近更新 更多