|
-
Apr 15th, 2010, 04:11 PM
#1
Thread Starter
Member
Call KeyUp Event Programatically
Hello All,
I am needing to call the KeyUp Event of my richtext box. Anyone know how I can do this?
rtbScript_KeyUp(Sender As Object, e As System.Windows.Forms.KeyEventArgs)
I'm not sure what I would enter into this.
I'm wanting to call the Period Key going up. I think the key is oemsPeriod or something like that
rtbScript_KeyUp(??, ??)
Not sure what I need to put in these two fields.
Thanks for all your assistance.
Mythos
-
Apr 15th, 2010, 04:41 PM
#2
Addicted Member
Re: Call KeyUp Event Programatically
well you could probably just do this....although i havent tested it....
Dim sample_e As New Windows.Forms.KeyEventArgs(Keys.OemPeriod)
rtbScript_KeyUp(nothing, sample_e)
-
Apr 15th, 2010, 04:42 PM
#3
Addicted Member
Re: Call KeyUp Event Programatically
You would create new KeyEventArgs and call the event with those, but just calling the event won't put text in the box. That's why the Text property of RichTextBox exists. Why on earth would you want to call the event directly?
Anyways..
vb Code:
Dim kea As New System.Windows.Forms.KeyEventArgs(Keys.A) RichTextBox1_KeyDown(Me, kea)
-
Apr 15th, 2010, 07:54 PM
#4
Re: Call KeyUp Event Programatically
You don't call events. Events are raised. You can't raise events of other objects. Only the object can raise its own events.
What you really mean is that you want to call the KeyUp event handler, which is actually a member of your form, not of the RichTextBox. The answer is that you don't. You really shouldn't ever be calling event handlers directly. If there is logic in the event handler that you want to execute at times other than when the event is raised then remove that code from the event handler. Put it into its own method which you can then call from anywhere you like, including the event handler. In short, if you currently have this:
Code:
rtbScript_KeyUp(Sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles rtbScript.KeyUp
'blah blah blah
End Sub
then change it to this:
Code:
rtbScript_KeyUp(Sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles rtbScript.KeyUp
DoBlah()
End Sub
Private Sub DoBlah()
'blah blah blah
End Sub
Now you can call DoBlah from anywhere else you like too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|