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

Super Context Menu Strip

By Hany Badrous

How to build a context menu that displays any group of controls
C#, Windows, .NET, Dev, Design
Version:3 (See All)
Posted:8 Jan 2008
Updated:5 Oct 2009
Views:39,911
Bookmarked:160 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
26 votes for this article.
Popularity: 6.66 Rating: 4.70 out of 5

1

2

3
6 votes, 24.0%
4
19 votes, 76.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 we do not use any control(s) on the context menu??? This will make the user interface easier to use and learn and even faster. 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 a 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. And now, I have a new and easier implementation.

How It Works

SuperContextMenuStrip is based on ContextMenuStrip which adds a user control to a ToolStripControlHost then adds the host as an item to the menu.

Using the Code

  1. Add a user control to your project and put any group of controls in it, the way you like, but make them public so that you can add event handlers to them.
  2. Override ProcessDialogKey in your user control and make sure it is as shown in the sample code.
  3. Please have a look at the main from source code, you will find it so easy to use it.

Known Bugs

I still have these bugs but I am working on them. If you have any 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 these 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

  • October 2009
    • Completely changed the structure (AGAIN) to make it easier to use
  • 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 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
Generala bug on example project Pinmembermheidari21:55 11 Jul '09  
GeneralRe: a bug on example project PinmemberHany Badrous3:48 12 Jul '09  
GeneralRe: a bug on example project Pinmembermheidari2:42 12 Aug '09  
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: 5 Oct 2009
Editor: Deeksha Shenoy
Copyright 2008 by Hany Badrous
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project