Introduction
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.
Properties:
private Image menuimage;
public Image MenuImage
{
get { return menuimage; }
set { menuimage = value; }
}
private string description = "";
public string Description
{
get { return description; }
set { description = value; }
}
private string caption = "";
public string Caption
{
get { return caption; }
set { caption = value; }
}
private string key;
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,
Description);
newitem.Key = key;
lstRootItems.Add(newitem);
return newitem;
}
And a QuickMouseMenuItem have two method to add child items:
public QuickMouseMenuItem AddChildQuickMouseMenuItem(
QuickMouseMenuItem childitem)
{
lstSubQuickMouseMenuItems.Add(childitem);
childitem.ParentQuickMouseMenuItem = this;
return childitem;
}
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;
}
else
{
childitem.menuimage = menustrip.Image;
}
tsmenuitem = menustrip;
lstSubQuickMouseMenuItems.Add(childitem);
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:
QMM.QuickMouseMenuUC quickMouseMenuUC1 = new QMM.QuickMouseMenuUC();
quickMouseMenuUC1.Size = new Size(200, 200);
quickMouseMenuUC1.HideOnMouseLeave = true;
quickMouseMenuUC1.NavigateOnHover = true;
foreach (Control act in this.Controls)
{
if (act is MdiClient)
{
act.MouseDown += new MouseEventHandler(
quickMouseMenuUC1.Parent_MouseDown);
break;
}
}
quickMouseMenuUC1.QuickMenuItemClicked +=new MouseEventHandler(
quickMouseMenuUC1_QuickMenuItemClicked);
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:
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");
file_menu.CreateChildQuickMouseMenuItemFromMenuStrip(newToolStripMenuItem);
file_menu.CreateChildQuickMouseMenuItemFromMenuStrip(closeToolStripMenuItem);
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 (http://www.devexpress.com/Products/NET/WinForms/Index.xml).
Enjoy it and vote.
History
Beta 1.