Click here to Skip to main content
15,311,151 members
Articles / Desktop Programming / Windows Forms
Posted 11 Aug 2007


41 bookmarked

My QuickMouseMenu

Rate me:
Please Sign up or sign in to vote.
2.87/5 (5 votes)
11 Aug 2007CPOL2 min read
My QuickMouseMenu



I am developing an Integrated System for a company, with lot of functionality (CRM, Invoicing, Store, Warranty Managemant, Treasury, etc.). So the application has lot of forms.

The first version of the app had a ToolStripMenu, with about 8-10 root menus and many submenus. Of course, the main features had shortcut keys, but not everybody likes shortcuts. Maybe we could use toolbars, but I don't like them, because you need to do toolbaritems for every menuitem, and it's so circumstantial...i think :)

I use DevExpress components in my applications, and they have a fantastic control: RibbonControl (Like new MS office 2007). I think it is a very-very usefull control with application menu, and statusbar and etc. (its usefull for users and usefull for developer, becaus u can add the same "Item" (same object with same handlers) to menu,to AppMenu, to Statusbar,etc...

But... the same problem with shortcuts and context menu... so i decided to make my own 'contextmenu', and it can work with DevExpress ribbon items ( not with all, but can with menus). For the 'pilot' project i made it for 2.0 MenuStrip...

Of course u can use it without menustrip!!!!

Using the code

Because it is a pilot project ( a pilot beta project) I have not made design support, error handling,etc for the Control. Really, it is not a Control, it is a Form, but if you need a UserControl or a Component, u can simply do it, with desing support...

The QuickMenuItem (class QuickMouseMenuItem)

Its a simple class to store a menuitem.


private Image menuimage;

/// <summary>
/// menu image
public Image MenuImage
    get { return menuimage; }
    set { menuimage = value; }

private string description = "";

/// <summary>
/// menudescription to tooltip
public string Description
    get { return description; }
    set { description = value; }

private string caption = "";

/// <summary>
/// menucaption to tooltip
public string Caption
    get { return caption; }
    set { caption = value; }

private string key;

/// <summary>
/// the key to identify the menuitem
public string Key
    get { return key; }
    set { key = value; }

How can u use it?!? Its very easy: the Control (class QuickMouseMenuUC)) have one method(with some overrides) to add root items:

public QuickMouseMenuItem AddQuickMouseMenuItem(string key, Image img,
                          string Caption, string Description)
    QuickMouseMenuItem newitem = new QuickMouseMenuItem(img, Caption,
    newitem.Key = key;

    return newitem;

And a QuickMouseMenuItem have two method to add child items:

/// <summary>
/// Add child menuItem
/// </summary>
/// <param name="childitem" />
/// <returns>
public QuickMouseMenuItem AddChildQuickMouseMenuItem(
                          QuickMouseMenuItem childitem)
    childitem.ParentQuickMouseMenuItem = this;
    return childitem;

/// <summary>
/// Add child menu from Menustrip with Click event!!!
/// </summary>
/// </returns>
/// <param name="menustrip">
/// <returns>
public QuickMouseMenuItem CreateChildQuickMouseMenuItemFromMenuStrip(
       System.Windows.Forms.ToolStripMenuItem menustrip)
    QuickMouseMenuItem childitem = new QuickMouseMenuItem();
    childitem.caption = menustrip.Text;
    childitem.description = menustrip.ToolTipText;
    if (menustrip.Image == null)
        childitem.menuimage = resQMM.defaultIMAGE;
        childitem.menuimage = menustrip.Image;
    tsmenuitem = menustrip;

    childitem.ParentQuickMouseMenuItem = this;
    return childitem;

If you want to use it with MenuStrip you need to use the second method, and if you want to use it with another menu, or toolbar, or etc, write your own method!!!

And the only one thing remains to use it, you need to add the control(Form) to your application, for example:

//create quickmenu
QMM.QuickMouseMenuUC quickMouseMenuUC1 = new QMM.QuickMouseMenuUC();

quickMouseMenuUC1.Size = new Size(200, 200);

//hide when leave, if false close than back click on top level
quickMouseMenuUC1.HideOnMouseLeave = true;

//if have submenu than navigate
quickMouseMenuUC1.NavigateOnHover = true;
foreach (Control act in this.Controls)
    //i add the handler to mdifrom mdiclient area
    if (act is MdiClient)
        // add to mouse down event
        // do it for that controls you want...
        act.MouseDown += new MouseEventHandler(

//QuickMenuItem click event...
quickMouseMenuUC1.QuickMenuItemClicked +=new MouseEventHandler(

The sample application contains a MDI app. demo with some demo menu, and it appears when the user click the mdiclient area. Some demo menuitems:

//add some test menu
quickMouseMenuUC1.AddQuickMouseMenuItem(respic.addd, "Add",
    "Adding new value...");
quickMouseMenuUC1.AddQuickMouseMenuItem(respic.cancel, "Cancel",
    "Cancel last operation...");
QMM.QuickMouseMenuItem file_menu = 
    quickMouseMenuUC1.AddQuickMouseMenuItem(respic.AppMenu32, "File",
    "File menu");
//add some test menu from toolstripitem

//some menu with sub menu...
quickMouseMenuUC1.AddQuickMouseMenuItem(respic.user, "Users", "Useres form");
QMM.QuickMouseMenuItem qmm_eamil = quickMouseMenuUC1.AddQuickMouseMenuItem(
    respic.email2, "email");

QMM.QuickMouseMenuItem qmm_print = qmm_eamil.AddChildQuickMouseMenuItem(
    new QMM.QuickMouseMenuItem(respic.print, "Print", ""));

qmm_eamil.AddChildQuickMouseMenuItem(new QMM.QuickMouseMenuItem(respic.sync,
    "Sync", ""));

qmm_print.AddChildQuickMouseMenuItem(new QMM.QuickMouseMenuItem(respic.copy,
    "Copy", ""));
qmm_print.AddChildQuickMouseMenuItem(new QMM.QuickMouseMenuItem(respic.addd,
     "Add printer", "add printer"));

Now its Done!!!

So its a simple "control", in a simple demo, if you like it, download and customize it, anyway you want, and your application needs!!!

I do this, in my application and with devexpress controls (

Enjoy it and vote.


Beta 1.


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


About the Author

Krisztian Batyai
Instructor / Trainer
Hungary Hungary
Born in the U.S.A...
'Of course NO... Born in Hungary...

and after it...

Nowdays i'm Electrical Engineer(MSc), Microsoft Certified Trainer and Developer...

MCT,MCPD 3.5,MCTS 3.5 WPF,WF,ADO.Net,WinForms

Comments and Discussions

GeneralMy vote of 2 Pin
Xmen Real 7-Aug-09 17:29
professional Xmen Real 7-Aug-09 17:29 
GeneralVery nice i'll take a look on it Pin
JoanComasFdz2-Oct-07 8:28
MemberJoanComasFdz2-Oct-07 8:28 
QuestionCould I use this to replace system context menu? Pin
Haydeng17-Aug-07 13:53
MemberHaydeng17-Aug-07 13:53 
AnswerRe: Could I use this to replace system context menu? Pin
Krisztian Batyai19-Aug-07 7:51
MemberKrisztian Batyai19-Aug-07 7:51 
GeneralWow! Pin
JoanComasFdz15-Aug-07 6:51
MemberJoanComasFdz15-Aug-07 6:51 
GeneralCorrupt zip files! Pin
Gary Noble13-Aug-07 3:35
MemberGary Noble13-Aug-07 3:35 
GeneralRe: Corrupt zip files! Pin
Krisztian Batyai13-Aug-07 4:03
MemberKrisztian Batyai13-Aug-07 4:03 
GeneralRe: Corrupt zip files! Pin
Blubbo16-Aug-07 1:47
MemberBlubbo16-Aug-07 1:47 
AnswerRe: Corrupt zip files! Pin
Krisztian Batyai16-Aug-07 2:37
MemberKrisztian Batyai16-Aug-07 2:37 
GeneralNice Pin
Pawel Gielmuda12-Aug-07 21:59
MemberPawel Gielmuda12-Aug-07 21:59 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.