Click here to Skip to main content
Click here to Skip to main content

Super Context Menu Strip

By , 5 Oct 2009
 
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
Engineer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionEventsmemberLonnie Nunweiler24 Apr '13 - 1:57 
Great control. For a static popup it is wonderful.
 
I have a popup where I want to modify the background color of a button to show the selected color from another part of my program.
 
In theory, I simply need to catch the focus event or enter event and set the color there. I have tried and tried but to no avail. The focus and enter do not seem to be available. I can add an override to the popper and it triggers but I am unable to do anything to the control to be popped up.
 
Is this possible and I am missing something obvious?
QuestionNested Popup Possible?memberMember 22710476 Mar '13 - 15:58 
I tried this to make nested popup....is it possible?
GeneralMy vote of 5memberJacobkingsly18 Feb '13 - 18:28 
One of the informative article
Questionhow to make it resizable !!memberA7mad_24 Oct '12 - 0:09 
Hello all,
 
First of all this is great and awesome article, Thx Hany Badrous. Wink | ;)
Now my point is how to make it resizable !!?
GeneralSuper GREAT !!memberMazen el Senih23 Mar '12 - 5:31 
Thank you hany keep up the cool things !
got my 10/2 !
GeneralMy vote of 5memberzaheer_sagitarius28 Feb '12 - 2:52 
Excellent work Smile | :)
QuestionAbsolutely Great!memberMikeDaMan259421 Jan '12 - 9:05 
This is amazing. It opens so many cool UI features that will make my programs differ from the others. This is absolutely amazing.
GeneralThis Control Has Changed ALL My ProgramsmemberMember 809931229 Dec '11 - 5:11 
Five stars for sure.
 
This control is VERY versatile. I've used it to create menu structures, selection dialogues, custom tooltips, and even markers on a map. Once I began using this control I came up with more and more ways I could use it.
 
I would post samples but I have used it just too many times to count. Fantastic work!
BugThe solution of the 2nd bugmembergrrrrr12 Dec '11 - 3:15 
Maybe this way will work. Before the user clicks on the part of the combo box's dropdown, using
 
PoperContainer p = this.Parent as PoperContainer;
p.AutoClose = false;
 
to cancel the autoclosing of the container, and set AutoCLose=true after finishing your job.
 
I find this way when I will show the contextmenu of a button in the PopedCotainer(the container is also closed)
 
sorry for my pool english.
Questionthe control I want to pop is a dynamic onememberidn197823 Nov '11 - 15:21 
but it doesn't work at all. It still showes the original control that I draw in the design mode.
Anyone can help me? Cry | :((

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 5 Oct 2009
Article Copyright 2008 by Hany Badrous
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid