Click here to Skip to main content
6,291,522 members and growing! (14,099 online)
Email Password   helpLost your password?
Desktop Development » Menus » Custom menus     Intermediate License: The Code Project Open License (CPOL)

Super Context Menu

By Hany Badrous

How to build a context menu that display any group of controls
C#, Windows, .NET, Dev, Design
Posted:8 Jan 2008
Updated:11 Jun 2008
Views:31,172
Bookmarked:131 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
22 votes for this article.
Popularity: 6.32 Rating: 4.71 out of 5

1

2

3
4 votes, 19.0%
4
17 votes, 81.0%
5
Picture1_small.JPG
Figure 1: You can put any group of controls on the pop-up context menu.

Introduction

Long time ago, I wondered how Microsoft Access put an Edit control on the context menu! Then I got another idea ... why don't we use any control(s) on the context menu? This will make the user interface easier to use, learn and increase productivity. The good news here is that, you can make it the same way you design a user control or a form using the Visual Studio designer.

Background

At first, I thought we could customize the Menu. Then I discovered that this is very hard and maybe impossible. I tried to make use of the Form, but this is not the right choice because when we show it, the parent form loses its focus. A context menu shouldn't cause that. Luckily, I found the very good article "Simple Pop-up Control" by Lukasz Swiatkowski. This article shows how to display a pop up control using the ToolStripDropDown class. Then I said, "I found it." I used that idea to make my idea: a context menu that contains any group of controls.

How it Works

Internally SuperContextMenu uses another class PopItUp which based on ToolStripDropDown which is responsible to show the user control as a pop up control.

Using the Code

  1. Copy the file NewInterfaceGuides.cs into your project folder. Then add it to your project. And build the application.
  2. Add a new user control to your project, and then change the base class from UserControl to NewInterfaceGuides.SuperContextMenu.
  3. Design that user control any way you like it using Visual Studio Designer, but make the control members public.
  4. In the form add a member of that user control.
  5. In the form constructor, after InitializeComponent() initialize it and add event handlers to the controls.
  6. To show the context menu, use ShowAsContextMenu() method
  7. Respond to the events handlers that fired from the controls on the menu to achieve your program functionalities
  8. If the user finished working with the menu (like clicked a button) and you want to close the menu, you can close it easily by calling its Close() method.

Known Bugs

I still have these bugs but I am working on them so if you have an idea how to solve these bugs, please, help me.

  1. If the pop-up menu is shown and the user clicks a MenuStrip, a ToolStrip or an item on them, it does not hide. It needs two clicks to hide!
  2. The System.Windows.Forms.ComboBox class behaves in a strange way. It closes the container when the user clicks on the part of the combo box's dropdown list that sticks out of the container area. So, make sure that the dropdown list is totally inside the area.

Suggested Add-on Features and Ideas

  • Add a small x button to close it.
  • Easily move it.
  • Allow resizing.
    (But I don't recommend those changes, because they violate the concept of a menu; but you may find it a good idea.)
  • You can use it to implement custom tool tip, intellisense menus like visual studio.

History

  • June 2008: completely changed the structure to make it easier to use. Solved the tab bug.
  • December 2007: first release.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Hany Badrous


Member

Occupation: Engineer
Location: United States United States

Other popular Menus articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh)FirstPrevNext
AnswerPossible solution for the two clicks to hide bug [modified] Pinmembertimbo9000014:46 14 Jan '09  
Generalawesome! PinmemberVCKicks20:20 21 Aug '08  
GeneralContext menu control Pinmemberpooja mehta2:18 16 May '08  
GeneralDo you think it's possible in VC6 ? Pinmemberbillooj4:46 10 Apr '08  
GeneralRe: Do you think it's possible in VC6 ? Pinmemberbillooj4:52 10 Apr '08  
GeneralRe: Do you think it's possible in VC6 ? PinmemberHany Badrous18:56 10 Apr '08  
GeneralNice work - but you can see the control in the taskbar PinmemberForceDragonX14:10 25 Mar '08  
GeneralRe: Nice work - but you can see the control in the taskbar PinmemberHany Badrous20:27 25 Mar '08  
GeneralRe: Nice work - but you can see the control in the taskbar [modified] PinmemberForceDragonX5:07 26 Mar '08  
GeneralRe: Nice work - but you can see the control in the taskbar PinmemberHany Badrous19:41 26 Mar '08  
GeneralRe: Nice work - but you can see the control in the taskbar [modified] PinmemberForceDragonX3:02 27 Mar '08  
GeneralCool, but leave the pope alone! Pinmember leppie 12:07 8 Jan '08  
GeneralRe: Cool, but leave the pope alone! PinmemberHany Badrous13:54 13 Jan '08  
GeneralNicely done! PinmemberMike Hankey8:06 8 Jan '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Jun 2008
Editor: Sean Ewington
Copyright 2008 by Hany Badrous
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project