Windows Develop Bookmark and Share   
 index > Windows Forms General > Simulating key presses in RichTextBox
 

Simulating key presses in RichTextBox

I'm developing a logging application, where the user enters some text in a RichTextBox (RTB). I want to be able to replay the users actions in another RTB, just as if the user was typing the same thing all over again.

I have tried to use SendKeys, but it has the following problems:
1. For some reason the Focus() method always returns false, which means I cannot focus the RTB, and it doesn't receive the keys.
2. I would prefer to avoid focus dependent solutions altogether.

The only other option I can think of, is to alter the contents of the RTB through the SelectedText property, but that would require me to reverse engineer the RTB and find out, what all possible combinations of keystrokes does to the content of the RTB. This also has some associated problems:
1. It's error prone. I could easily overlook a key combination or have subtle differences in the output.
2. It's boring and not very elegant...

Any clever ideas to solve my problem would be highly appreciated!
lemvigh  Monday, September 07, 2009 2:58 PM
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
RichTextBox2.Text = RichTextBox1.Text
End Sub



Thanks

â™?My Blog â™?My Flickr â™?My Facebook â™?YOUR Place to have fun time !
Omie  Monday, September 07, 2009 3:42 PM
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
RichTextBox2.Text = RichTextBox1.Text
End Sub



Thanks

â™?My Blog â™?My Flickr â™?My Facebook â™?YOUR Place to have fun time !
Omie  Monday, September 07, 2009 3:42 PM

I also think textChanged event is better then sendkeys method. RichTextBox1.Focus() will set richtextbox1 on focus. Then use sendkeys.send method will send the key to richtextbox1.


Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Monday, September 14, 2009 8:09 AM

You can use google to search for other answers

Custom Search

More Threads

• My CurrentThread Principal is getting changed in Security
• How to know user is moving from a row in datagrid.
• Use which platform to develop GUI?
• Disabled control Fore Color
• toolpain control??
• How to make the Leave event fire on a control on dispose
• Major Database issue
• openfiledialog default view....fixed yet?
• I would like to select a particular text as bold
• How to validate the date entered in the text box? - Vb.net or VS 2005