Click to See Complete Forum and Search --> : Individual Toolbar button event handlers


kyoko
February 11th, 2004, 07:07 PM
I know that in c# with windows forms, there is a toolbar click event handler which is triggered when any of the buttons in the toolbar is clicked. Now I need to have separate event handlers to different buttons in the toolbar. I know that it could be done by using the general toolbar click event handler as a dispatcher. But this way seems to add a un-necessary indirection into the code. i am wondering if there is a more elegant way of doing that? for example, can we treat toolbar buttons as regular buttons and add click event to the buttons?

Thanks.

pareshgh
February 11th, 2004, 11:39 PM
in that case i would suggest to create a usercontrol of your own which will accept arraylist of button/ stringnames,
which in turn will fire event (using delegates)
these events will also contain information which button was clicked, button string etc.

what else in the other case you are looking for ?

kyoko
February 12th, 2004, 09:24 PM
Creating a user control is too much trouble for realizing this. i think I will just use a dispatching method.
I just don't understand why .Net doesn't have individual toolbar button event handlers. And toolbar button is not inherited from Button.

jigen3
February 14th, 2004, 05:32 PM
yes i was a bit surprised by the new toolbar message handling scheme, but if you use a switch statement on the toolbar text, it reads quite clearly.

Andy Tacker
February 16th, 2004, 02:00 AM
jigen is correct.
you can use switch statement to distribute events among the tool bar buttons.
you can create separate functions and perform some operations. if you so want, you can pass any parameters to this function, including sender control and event arguments.