Results 1 to 3 of 3

Thread: [2005] Raise event of another control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    [2005] Raise event of another control

    I'm working on a user control and I want to be able to raise the event of the UserControl "Click" when the user clicks on a different control.

    So I have 1 control, a button and I have a user control. When the button is clicked, it raises the Click event for the user control.

  2. #2
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    Re: [2005] Raise event of another control

    Something like this?
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Button2.PerformClick()
    End Sub
    That is how you would do it with two buttons. I'm not sure how to add something like .PerformClick to your user control, though.

    I suppose you could make the click sub Public.
    VB.Net 2008
    .Net Framework 2.0

    "Must you breathe? 'Cause I need heaven..."

  3. #3
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: [2005] Raise event of another control

    In your user control declare the event click and raise it inside a method (public sub). Then handle the click event of the button and call the method of your usercontrol. The click event of the user control will then be raised.

    UserControl:

    Code:
    Public Event Click()
    Public Sub RaiseMyClick()
      RaiseEvent Click()
    End Sub
    Button Code:
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
         MyUserControl.RaiseMyClick()
    End Sub

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