CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Posts
    104

    Individual Toolbar button event handlers

    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.

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    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 ?
    - Software Architect

  3. #3
    Join Date
    Jan 2003
    Posts
    104
    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.

  4. #4
    Join Date
    Mar 2003
    Posts
    164
    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.

  5. #5
    Andy Tacker is offline More than "Just Another Member"
    Join Date
    Jun 2001
    Location
    55°50' N 37°39' E
    Posts
    1,503
    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.
    If you think you CAN, you can, If you think you CAN'T, you are probably right.

    Have some nice Idea to share? Write an Article Online or Email to us and You may WIN a Technical Book from CG.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured