how to programatically raise keyPress event of a user control?
-
I have a user control that contains a textbox control. I am getting some data from serial port. Anytime i get this data I need to raise keypress event of the user control that should internally riase keypress event of text box. I am a newbie to winforms and will very much appreciate if someone can walk me through steps on how to do this.
-
I have a user control that contains a textbox control. I am getting some data from serial port. Anytime i get this data I need to raise keypress event of the user control that should internally riase keypress event of text box. I am a newbie to winforms and will very much appreciate if someone can walk me through steps on how to do this.
Hi, two comments: 1. are you sure you want KeyPress events? if all you want is append some text to a TextBox, why not use the TextBox.AppendText() method? 2. if you use SerialPort.DataReceived event, you must be aware that event does not fire on the main/GUI thread; hence you cannot directly touch GUI Controls, you will need Control.InvokeRequired and Control.Invoke. If those are unfamiliar, search for InvokeRequired. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, two comments: 1. are you sure you want KeyPress events? if all you want is append some text to a TextBox, why not use the TextBox.AppendText() method? 2. if you use SerialPort.DataReceived event, you must be aware that event does not fire on the main/GUI thread; hence you cannot directly touch GUI Controls, you will need Control.InvokeRequired and Control.Invoke. If those are unfamiliar, search for InvokeRequired. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
Thanks for your response. My real problem is much more complicated so I am just used a simple example. All I basically need is to know how can I programatically raise keypress event of a text box that is contained within a user control. Any code example will be highly appreciated
-
Thanks for your response. My real problem is much more complicated so I am just used a simple example. All I basically need is to know how can I programatically raise keypress event of a text box that is contained within a user control. Any code example will be highly appreciated