I am writing a user control derived from System.Windows.Forms.Control.
The control uses the event Control.KeyDownto view keystrokes: I have to handle a few keystrokes (for example <Ctrl>-K) as hot keys, which is why I launch the dialog box.
If I started the dialog from my event handler onKeyDown, the dialog will appear before I set KeyEventArgs.SuppressKeyPressin trueand return (and therefore I can not suppress the click K). Instead, I would like to return from the event handler onKeyDownand start the dialog after that. To do this, after I return from the event handler onKeyDown, I need to somehow call it with some kind of "start dialog" event.
In Win32, I can generate this event using the API PostMessageto send a registered window message to myself: I would receive this message immediately after any previous message in the message queue and use it as a signal to start my dialog. However, here I cannot use a function PostMessage(or method WndProc) because I want to use strictly managed APIs (unnecessarily SecurityPermissionFlag::UnmanagedCode).
So, what would be the managed equivalent for a thread (my UI thread) for scheduling an asynchronous callback: maybe some kind of timer? Some kind of self Invoke?
source
share