Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Usercontrol Events

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Resolved [RESOLVED] [2005] Usercontrol Events

    Hey,

    I am using some usercontrol that contains an RichTextBox.
    I didn't create the user control myself, but I have been trying to understand how it works.


    I needed the "RTB_SelectionChanged" event in my program, but noticed that it wasn't there... It's just not in the list.

    So I had a look in the usercontrol's code. I can see a whole lot of events being declared, like this for example:
    Code:
        Private Sub RTF_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RTF.KeyPress
            'raise up the event
            Me.OnKeyPress(e)
        End Sub
    There was also a "Private Sub RTF_SelectionChanged" event, with some code in it, so I still didn't know why it didn't show...

    Then I noticed the following..:

    In the RTF_KeyPress example, there is the line "Me.OnKeyPress(e)" which, according to the comments, raises the event...

    So I tried adding the same line to the SelectionChanged event:

    Code:
        Private Sub RTF_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RTF.SelectionChanged
    
            'Some code here
    
            'Raise the event
            Me.OnSelectionChanged(e)
        End Sub
    However, VS says it doesn't know "Me.OnSelectionChanged"... Huh?
    OnSelectionChanged is not a member of <usercontrol name>...


    How can I make it have the SelectionChanged event?!

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] Usercontrol Events

    in your usercontrol declarations put

    vb Code:
    1. Public event RTF_SelectionChanged

    then

    vb Code:
    1. Private Sub RTF_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles RTF.KeyPress
    2.      'raise up the event
    3.      raiseevent RTF_SelectionChanged
    4. End Sub
    5.  
    6. in your parent form you'll have a RTF_SelectionChanged event which will be called every time you raise the event

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2005] Usercontrol Events

    Thanks!

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