I’m implementing a custom Button class that inherits from System.Windows.Forms.Button, I do a custom paint of the button, including the button text. I want to support accelerator keys (hotkeys) for my buttons.
Little explanation: In an standard button, when the ALT key is pressed, the accelerator character is underlined:
button.Text = "&Capture screen";
When you press ALT key in the application, the button underlines the “C” charater.
So, when I paint the button text, I need to know when accelerator underlines are active or not, to draw my text underlined or not.
- How could I subscribe to receive accelerator messages?
- Is an event?
- Is a WND_PROC message?
- Is there managed code to get it?
Thanks in advance.
If you want to detect whether the Alt key was pressed inside the Paint event handler of the button, you have check the ModifierKeys property of the form: