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

Office 2003 Menus

By , 23 Feb 2004
 

Introduction

Just with one Single Line of code, you can change the look of all Menus and Context menus of your Windows Forms Project to look just like the menus shipped with Office 2003. Also, you can add Icons to your menus with a single line of code. There is one more feature in this component, You can simple call the method End to change the menus to its original look.

Using the code

To use the Component, First, add the component to the Toolbox, and then drag it to the form, and then just call this Method:

// To start showing the Office 2003 Menus
OfficeMenus1.Start( FormName );

Also, you can change the look of the menus to its original look by calling this method:

// to change the look of the menus to its original "classic" look
OfficeMenus1.End();

Adding Icons to Menu Items is very simple, Just add an ImageList to your project, and then change the ImageList property of your OfficeMenu Component to the ImageList you wish to use, and then use this code:

// Adding a picture to your Menus
// OfficeMenus.AddPicture( MenuItem MenuItemToAddPictureTo, int ImageIndex );
OfficeMenus1.ImageList = imageList1;
OfficeMenus1.AddPicture(menuItem2, 1);

Points of Interest

I was so confused about the way i will add pictures to menus, so i decided to add a collection of type NameValueCollection, and when we call the method AddPicture it will add the Handle of the menu and the Image index to that Collection, and when we want to retrieve the image of a menu, we search this collection for the handle of the menu, if found it returns the picture, otherwise it returns null. Check the code for more information. BTW, the code is well commented.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mohammed Halabi
Saudi Arabia Saudi Arabia
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   
QuestionLicense termsmemberRotted Frog12 Nov '12 - 1:18 
5 stars for the excellent code and article, but I want to use it in a commercial project. Can you let me know the license terms?
QuestionUpdated Code?memberkevinlkingma17 Nov '06 - 5:06 
Hi:
 
Do you have updated code with all the bug fixes for the Office 2003 control?
GeneralGood Control: But.....memberSameers (theAngrycodeR )22 Oct '06 - 15:02 
Very Nice contol. Quick and easy to use, but limited in some functionalties for example, context menu, tray icon menu etc. Also, once you have called the Start method, there is no way to change icon of menu item.
 
I had two context menus which are associated with controls dynamically. When I called Start method, it didn't applied theme on them, even I tried with associated ContextMenu with controls (ListView) before calling it, but didn't worked. however, when I assigedn one context menu to form itself, it worked.
 
IF this control has support for Context Menu and runtime image updation, then i think this will be the best one. I think to change icons at runtime, there is one 'tweak' (Just thought about while writing this message), that is, stop and start it again. I believe it should work. Will test now.
 
But ***** from me. Since this is really best effort.
Good Luck
Sameers
 
Need custom software? Contact DevelopersINN[^]
Need to add reminders for your Outlook emails? Try Outlook Personal Assistant[^]

GeneralProblem With images in a menumemberIndarjeet28 Aug '06 - 23:49 
When I move over the menu the images appear and disappear frequently.
 
So Please Solve this.
 
Hello All,

GeneralThe problem about the contextmenumembersleet_t12 Dec '05 - 22:23 
hi,
yes it is a great control,but there is a problem about the contextmenu, when I create a richTextBox and add contextMenu but I can'nt find the image icon
in the menu.
wo can help me?Sniff | :^)
GeneralBug Report : Menu DisappearsmemberMrEyes27 Nov '05 - 13:51 
All in all this is a great control, so first let me say well done.
 
But as the title of the thread suggests I have found a bug, that I am at a loss to explain.
 
I have placed the Menu control as the MainMenu for an MDI parent form, when this form loads it loads references to all the MDI children (via reflection) (each MDI child is in its own class library). When I open 2 mdi children and then close them the MainMenu seems to self destruct.
 
I know self destruct is a poor explanation so this is what basically happens. When the second MDI child is closed all text from the MainMenu disappears. If I click on now empty MainMenu it does popup the sub menus but these have no text. If I click where there should be an entry the request event is fired and the MainMenu suddenly gets its items back.
 
Does anybody know what could be causing this, as it would be a real shame to have to drop the component for this.
 
EDIT:
I am quite confident that it is the control causing this as if I put a "return;" at the top of the Start(...) function (effectively disabling the control) I do not get this bug
 
EDIT 2
As a test I created a simple test app that doesnt do any of that fancy reflection loading. A simple project with 2 forms: an MDI parent and an MDI child. Both forms have MainMenus on them one of the MenuItems on the parent shows the child form. If I launch a single child form I can open and close to my hearts content, if I open 2 child forms, when i close them both the MainMenu disappears as described above. If I remove the MainMenu component from the child MDI form the problem disappears. I am fairly confident that this has something to do with the redraws but at the moment I am at a loss to explain it.
 
EDIT 3
A little more investigation has found that if I have an MdiList MenuItem, this is still visible when all other menu components disappear. On a side note there is still the bug as described in the post "Using MdiList in Menu" where the MdiList menu items are not rendered with the MSO 2K3 style.
QuestionContext MenuesmemberGolden Dragon9 Oct '05 - 12:24 
Hi,
 
I am trying to make this work with context menues, but I had no success so far.
 
I have one main form with regula top menues, and that is OK, Office Menues work. I have a listview on the main form with one context menu, and this menu doesn't have a office look, as it could be expected. And I have one more form with one more listview, and that control also have context menu, and this one is also without office look. How to make this control to work with both of the context menus? Should I start control on every form separatly or not?
 
Millan
 
-- modified at 18:26 Sunday 9th October, 2005
AnswerRe: Context MenuesmemberJosma3 May '06 - 23:29 
You have to change the Call in file 'officeMenus.cs'
 
There is a code in which all Controls of the form will be enumerated. But this methode has to be called recursive.
 
In the Methode 'Start' in file 'officeMenus.cs'
replace the call with this Methode
 
this.InitContextMenues(form.Controls);
 
I don't know the exact Position in Source file. Sorry.
 
Here is the Code for the Methode InitContextMenues:
private void InitContextMenues (Control.ControlCollection yControls)
{
foreach ( Control c in yControls )
{
this.InitContextMenues(c.Controls);
 
if ( c.ContextMenu != null )
InitMenuItem(c.ContextMenu);
}
}
}
 
Don't forget to do so for the Unlink (End) Methode!!!
 
Hope it helps!
And sorry for my bad English
Generali want to learn program by VC++memberthanhvu4 Oct '05 - 21:39 
I want to use mouse to choose a object on display( use to move a object or edit it). But i don't write code. Can you show me a way to write code?
Thank you very much.
 
thanhvu
Questionhow can a draw a line separator?memberaxelbrian8 Sep '05 - 6:09 
how can a draw a line separator?

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 24 Feb 2004
Article Copyright 2004 by Mohammed Halabi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid