Redirecting keystrokes to a RichTextBox Control in C#
-
I have a Form with a few panels and a RichTextBox on it. I need to detect any key messages on the level of form and send them to other child controls on my own way. I tried calling/overriding WndProc, PreProcessMessage, etc. Also tried setting my own MessageFilter via Application.AddMessageFilter() and finally gave a try to a native method SendMessage. None of these work. I CAN detect the messages. But the problem is that when I'm passing them to the RichTextBox there's no effect (no text is appended). How can I make that control react on the redirected messages? Thanks in advance.
-
I have a Form with a few panels and a RichTextBox on it. I need to detect any key messages on the level of form and send them to other child controls on my own way. I tried calling/overriding WndProc, PreProcessMessage, etc. Also tried setting my own MessageFilter via Application.AddMessageFilter() and finally gave a try to a native method SendMessage. None of these work. I CAN detect the messages. But the problem is that when I'm passing them to the RichTextBox there's no effect (no text is appended). How can I make that control react on the redirected messages? Thanks in advance.
Why can't you do it on the level of keydown, keypress and keyup messages ? Why can't you just detect a keydown and pass the focus to the control ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Why can't you do it on the level of keydown, keypress and keyup messages ? Why can't you just detect a keydown and pass the focus to the control ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Firstly, when a key is pressed, I need to add a char to the textbox, even if it does NOT have focus. Then, when I press a key, the keydown event is obviously not detected by the textbox. The same with the form! There is no info about this event. I could use PreviewKeyDown, but I couldn't mark the message as used/handled. Secondly, the form should distribute the messages, not necessarily to the box. Maybe somewhere else, basing on other conditions.