Results 1 to 4 of 4

Thread: Call KeyUp Event Programatically

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Question 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

  2. #2
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196

    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)

  3. #3
    Addicted Member DramaQueen's Avatar
    Join Date
    Mar 2010
    Posts
    187

    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:
    1. Dim kea As New System.Windows.Forms.KeyEventArgs(Keys.A)
    2.         RichTextBox1_KeyDown(Me, kea)

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width