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

RE: How to raise an event? by PhilWilliams

PhilWilliams
Tue Sep 20 17:21:02 CDT 2005

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

All the best,
Phil.

"Andreiwid" wrote:

> 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
>
>

Re: How to raise an event? by Lloyd

Lloyd
Tue Sep 20 23:05:56 CDT 2005

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().

"Andreiwid" <Andreiwid@discussions.microsoft.com> wrote in message
news:15C324E9-2C67-445A-B2F1-DD8A4B4DBFD9@microsoft.com...
> 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
>
>