|
-
Sep 18th, 2002, 12:39 PM
#1
Thread Starter
New Member
calling Toolbar button click event through code
Anyone know how to call the Toolbar_Click event from code?
I've code to handle the basic user clicks (from the form) but want to fire the code behind a toolbar button ("Save") through code.
Thanks,
O.
-
Sep 22nd, 2002, 02:49 AM
#2
Junior Member
Assuming that your toolbar is called 'ToolBar':
VB Code:
Private Sub ToolBar_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar.ButtonClick
Select Case ToolBar.Buttons.IndexOf(e.Button)
Case 0 ' The first button
MsgBox("You pressed the new button")
Case 1 ' The second button
MsgBox("You pressed the save button")
End Select
End Sub
-
Sep 24th, 2002, 08:34 AM
#3
Thread Starter
New Member
Thanks, but that's the code to handle the event. I'm trying to call the ButtonClick event of the toolbar directly from code. In VB6 one might do something like so:
Call Command1_click
Looking for whatever .NET format allows me to do this with the toolbar.
O.
-
Sep 24th, 2002, 10:18 AM
#4
You do it the same as in VB6 only you have to pass the proper parameters along too.
VB Code:
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
'handle click event
MsgBox(String.Concat("You pushed button # ", ToolBar1.Buttons.IndexOf(e.Button)))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'FIRE click event
ToolBar1_ButtonClick(ToolBar1, New ToolBarButtonClickEventArgs(ToolBarButton1))
End Sub
-
Sep 24th, 2002, 10:20 AM
#5
Thread Starter
New Member
Excellent, thank you Edneeis I'll give it a shot.
It was the parameter format I couldn't figure out.
O.
-
Sep 24th, 2002, 10:23 AM
#6
Alright its:
SubThatHandlesEvent(ToolbarControl, New ToolBarButtonClickEventArgs(ToolbarButtonObject)
-
Sep 24th, 2002, 10:31 AM
#7
Thread Starter
New Member
Again, thank you very much. Just tested your advice and it worked perfectly. Thanks for the help.
O.
-
Sep 24th, 2002, 10:33 AM
#8
Thread Starter
New Member
Just out or curiosity, where did you find information on passing the New ToolBarButtonClickEventArgs(buttonobject)?
O.
-
Sep 24th, 2002, 10:54 AM
#9
In the declaration of the event in the sub that handles it:
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
Most EventArgs Inherited object just accept the added parts into the constructor and the button is the added part. I do the samething when I'm making objects and have to add to the eventargs. I think it just takes a little getting used to the new 'system' for events, but once you do it makes things much easier having everything fairly standardized.
You can also use the Help or Object Browser to check out the custom EventArgs.
-
Sep 24th, 2002, 12:08 PM
#10
New Member
Just that I understand, wouldn't it be easier to create a procedure that is being called from either the ToolBar's click event or any other part of your program?
best regards
Sascha
-
Sep 24th, 2002, 12:21 PM
#11
Thread Starter
New Member
That is something I did while trying to find the answer to my question. It's a matter of personal choice I suppose but I'd rather not go another function deep if/when the toolbar ButtonClick event can be used.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|