October 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Owner-Draw Menus with .NET and Managed C++

  • April 29, 2005
  • By Tom Archer
  • Send Email »
  • More Articles »

Putting Everything into a Class

Now, condense everything into a more usable C++ class called ACG::MenuItem. Instead of redisplaying the same code already presented in the previous section, this section shows you only how to use the example class:
  1. Copy the ACG::MenuItem class from the demo project into your project.
  2. Insert the following code into your application's form-load method:
    // Instantiate the top level menu
    MenuItem* menuFile = new MenuItem(S"&File");
    mainMenu1->MenuItems->Add(menuFile);
    
    // Instantiate the owner-draw menu, specifying the 
    // "click" event handler, font, and font's point size
    ACG::MenuItem* menuExit = 
      new ACG::MenuItem(S"E&xit", 
                        new EventHandler(this, ExitClick),
                        S"Comic Sans MS",
                        16);
    
    menuFile->MenuItems->Add(menuExit);
    
  3. Implement the "click" event handler:
    private: void ExitClick(Object* sender, EventArgs* e) 
    {
      this->Close();
    }
    

Download the Code

To download the code for the demo application, click here.

About the Author

Tom Archer owns his own training company, Archer Consulting Group, which specializes in educating and mentoring .NET programmers and providing project management consulting. If you would like to find out how the Archer Consulting Group can help you reduce development costs, get your software to market faster, and increase product revenue, contact Tom through his Web site.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel