How to raise an event?

G

Guest

Hi guys!

I've an event that belongs to a ToolBar:

Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
...
End Sub

I'd like to know how can I raise that event manually, throught a TextBox
KeyPress event:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Convert.ToChar(Keys.Return) Then
ToolBar1_ButtonClick(ToolBar1,
System.Windows.Forms.ToolBarButtonClickEventArgs.Empty)
End If
End Sub

I tried that code, but it didnt work.

thanks
 
G

Guest

Try (in C#)
toolBar1_ButtonClick(toolBar, new ToolBarButtonClickEventArgs(toolBarButton1))

All the best,
Phil.
 
L

Lloyd Dupont

Only the owner of an event could raise it.
Not even a subclass could!
To override such limitation object with event usually provide a method to
generate the event, which is usually protected (only available to subclass),
such as OnClick(), OnResize(), etc...
sometimes they even provide public method, such as Button.PerformClick().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top