Show keyboard shortcuts at all times

Is it possible to make an underlined hotkey always visible on my controls without pressing the Alt key on a Windows form using Visual Studio - C #?

I only have a certain time when I need the form controls to always be underlined with "_" under the symbol. Therefore, it would be nice to have only code for this.

I may have a setting for Windows to always show underlining shortcuts and hot keys, but I need this to happen at a specific time.

+3
source share
1 answer

Assuming you are using WinForms, you should rely on the underlying Win32 engine. And this message is WM_UPDATEUISTATE . The documentation states:

The application sends a WM_UPDATEUISTATE message to change the state of the user interface for the specified window and all its child windows.

So, you can send a message to the handle of the top-level window. You must pass UIS_CLEAR for the low word wParam and UISF_HIDEACCEL for the high order word wParam .

Here is a pretty crude code example. Keep in mind that my C # experience is very limited.

 public partial class Form1 : Form { private const uint WM_UPDATEUISTATE = 0x0128; private const uint WM_QUERYUISTATE = 0x0129; private const uint UIS_CLEAR = 2; private const uint UISF_HIDEACCEL = 0x2; public Form1() { InitializeComponent(); } private void Form1_HandleCreated(object sender, PaintEventArgs e) { ClearHideAccel(); } private void ClearHideAccel() { UIntPtr wParam = (UIntPtr)((UISF_HIDEACCEL << 16) | UIS_CLEAR); NativeMethods.SendMessage(this.Handle, WM_UPDATEUISTATE, wParam, IntPtr.Zero); } } internal class NativeMethods { [DllImport("User32", SetLastError = true)] public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam); } 
+8
source

All Articles