Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Event Handler Wizard

Event Handler Wizard

Scheduled Pinned Locked Moved C#
csharpc++designquestionannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cliff Hatch
    wrote on last edited by
    #1

    I never had any problems creating and finding event handlers using the C++ V6.0 ClassWizard but I don't find C# so easy to use in this respect. I have resorted to editing the code without the aid of a wizard on many occasions but I'm sure this can't be the best way - I imagine I'm missing something obvious:confused:. I have two specific questions: How do you add an event handler to a Toolbar button? Double clicking doesn't do anything, if you right click there is no "add event handler" option, and the Control Events button does not appear on the Properties view. All these things work with Dialog buttons, why not with Toolbar buttons? How do you create and locate handlers for UPDATE COMMAND UI messages? The V6.0 ClassWizard used to show these clearly but I can't find any reference to them on the C# Event Handler Wizard or the Properties view. Any assistance would be greatly appreciated. Best Regards Cliff Hatch

    M C 2 Replies Last reply
    0
    • C Cliff Hatch

      I never had any problems creating and finding event handlers using the C++ V6.0 ClassWizard but I don't find C# so easy to use in this respect. I have resorted to editing the code without the aid of a wizard on many occasions but I'm sure this can't be the best way - I imagine I'm missing something obvious:confused:. I have two specific questions: How do you add an event handler to a Toolbar button? Double clicking doesn't do anything, if you right click there is no "add event handler" option, and the Control Events button does not appear on the Properties view. All these things work with Dialog buttons, why not with Toolbar buttons? How do you create and locate handlers for UPDATE COMMAND UI messages? The V6.0 ClassWizard used to show these clearly but I can't find any reference to them on the C# Event Handler Wizard or the Properties view. Any assistance would be greatly appreciated. Best Regards Cliff Hatch

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Cliff, .NET is a bit different than MFC. By doubleclicking a control in the visual designer you'll get an event handler created for the control's default event. If you want to add any other eventhandler visually, then you'll have to use the Control Events button to show the events a selected control supplies (and which are marked designer-visible). Nevertheless, adding event handlers manually is just as easy. For example, adding a click event handler to a button in VS.NET can be achieved by typing myButton.Click += and then TAB twice. VS.NET finishes the statement and adds a new myButton_Click() event handler with the correct signature. If the Control Events button doesn't appear for a certain control then this control doesn't have any public visible events. Regarding the click on a ToolButton, this event is fired by the ToolBar containing the button. And for menus, there's the Popup event that's fired just when a menu is about to appear, so you can use this event to enable/disable your menu items. Regards, mav

      C 1 Reply Last reply
      0
      • M mav northwind

        Cliff, .NET is a bit different than MFC. By doubleclicking a control in the visual designer you'll get an event handler created for the control's default event. If you want to add any other eventhandler visually, then you'll have to use the Control Events button to show the events a selected control supplies (and which are marked designer-visible). Nevertheless, adding event handlers manually is just as easy. For example, adding a click event handler to a button in VS.NET can be achieved by typing myButton.Click += and then TAB twice. VS.NET finishes the statement and adds a new myButton_Click() event handler with the correct signature. If the Control Events button doesn't appear for a certain control then this control doesn't have any public visible events. Regarding the click on a ToolButton, this event is fired by the ToolBar containing the button. And for menus, there's the Popup event that's fired just when a menu is about to appear, so you can use this event to enable/disable your menu items. Regards, mav

        C Offline
        C Offline
        Cliff Hatch
        wrote on last edited by
        #3

        mav Thankyou for your clear reply. I now understand why the system behaves as it does, and I will try your method of adding handlers manually. I'm still puzzled why the designers of .NET chose this route though. I wonder if they planned to discard MFC's wizard support for the creation of ToolButton and Update handlers, or if this was an unintended side effect of design rationalisation. Best Regards Cliff

        1 Reply Last reply
        0
        • C Cliff Hatch

          I never had any problems creating and finding event handlers using the C++ V6.0 ClassWizard but I don't find C# so easy to use in this respect. I have resorted to editing the code without the aid of a wizard on many occasions but I'm sure this can't be the best way - I imagine I'm missing something obvious:confused:. I have two specific questions: How do you add an event handler to a Toolbar button? Double clicking doesn't do anything, if you right click there is no "add event handler" option, and the Control Events button does not appear on the Properties view. All these things work with Dialog buttons, why not with Toolbar buttons? How do you create and locate handlers for UPDATE COMMAND UI messages? The V6.0 ClassWizard used to show these clearly but I can't find any reference to them on the C# Event Handler Wizard or the Properties view. Any assistance would be greatly appreciated. Best Regards Cliff Hatch

          C Offline
          C Offline
          Cliff Hatch
          wrote on last edited by
          #4

          After a bit more exploration I found that I had indeed missed something: If you right click on menu items and select the "add event handler" option, the Event Handler Wizard appears and gives you the option to create or edit COMMAND and UPDATE_COMMAND_UI messages - so that's where they're hidden! The rule seems to be: right click on the thing you want to create a handler for and the Event Handler Wizard will provide pretty much the same functionality as MFC's ClassWizard - except that it doesn't work for toolbar buttons because you don't get an opportunity to call it up. I suppose one way round this is always to build a menu item first, attach handlers to it, then build a toolbar button with the same ID - and it will share the same handlers. Perhaps it is good practice to replicate every toolbar function in a menu, so maybe this approach makes sense. On the other hand, I don't see why a right click on the toolbar shouldn't offer the "add event handler" option. The treatment of toolbar buttons seems inconsistent with that of menu items and dialog buttons. Best Regards Cliff

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups