[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.
Re: [2005] Raise event of another control
Something like this?
Quote:
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.
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