Click here to Skip to main content
13,086,264 members (66,246 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 1 Jul 2004

Creating and Deleting Custom Menus in Visio using C#

Rate this:
Please Sign up or sign in to vote.
Creating the Visio custom menus and handling the click event from C# programs.This project requires that Visio application should run and it requires a default drawing to be open.


There are several ways to handle the menus in the Microsoft Visio application, but there are no events generated when the user clicks the menu. The best way to handle the menus and menu event handling is through CommandBars. Most of the sites I went never had a solution. Some of the forums mentioned an idea of how to implement. I needed something quicker to find a solution. Then I got through CommandBars. Hope this article will help you in all aspects in handling the menu bar.

With this article, you can not only to handle the menus in Microsoft Visio, but also the menus in some other Microsoft applications. E.g.: Microsoft Word, Microsoft Excel, Microsoft Outlook, etc.

This article concentrates more on Microsoft Visio. In this article, I will show you how to create custom menus and how to handle menu click event handlers.

This demo needs 2 components to be added: those are Microsoft Office 11.0 Object Library, Microsoft Visio 11.0 Type Library.


This demo contains CustomMenu class which will take care of setting the custom menus, and deleting a custom menu from the standard menu bar of the Visio application.

Let us start with the using declaration:

using Visio=Microsoft.Office.Interop.Visio;

The above statement includes Microsoft Visio interop services.

Secondly, private variables declaration:

private Microsoft.Office.Core.CommandBars commandBars;
private Microsoft.Office.Core.CommandBar commandBar;
private Microsoft.Office.Core.CommandBarButton commandBarButton;

The above variables are use to hold the standard CommandBars of Microsoft Visio application.

private Visio.Application visioApplication;
object visioObject = Marshal.GetActiveObject("Visio.Application");
this.visioApplication = visioObject as Visio.Application;

The above statements holds the visio application reference.

To get the built in menus from the Visio application, the following statement will work:

Visio.UIObject uiObject = this.visioApplication.BuiltInMenus;

After adding the menu to the menu bar, it should be set to standard menu bar of the Visio application with the following statement:


To get the standard CommandBars of the Visio application, the following statement has to be executed:

  (Microsoft.Office.Core.CommandBars) this.visioApplication.CommandBars;


*This demo requires that Visio application should be run, and it requires a default drawing to be open.


CommandBars can be used for a lot of things: creating menu bars, tool bars, etc. I feel CommandBar is the best way to handle Microsoft applications in your code, and you can play with the applications. I hope you can make good use of this code in your own projects.


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

Shashidhar Rao Nellutla
Software Developer (Senior)
United Kingdom United Kingdom
Completed Masters in Computer Applications.

You may also be interested in...


Comments and Discussions

QuestionMuyyyyyy Bueno Pin
Member 82953293-Nov-12 6:34
memberMember 82953293-Nov-12 6:34 
GeneralMenu in Visio Drawing Control Pin
ustim20-Jan-10 1:29
memberustim20-Jan-10 1:29 
GeneralToolBar in Visio Pin
sunil kumar verma16-Oct-07 18:00
membersunil kumar verma16-Oct-07 18:00 
GeneralSub menu in a menu item(Visio) Pin
sunil kumar verma7-Oct-07 18:56
membersunil kumar verma7-Oct-07 18:56 
GeneralRe: Sub menu in a menu item(Visio) Pin
lotfi.boutefaha11-Nov-08 3:18
memberlotfi.boutefaha11-Nov-08 3:18 
GeneralRe: Sub menu in a menu item(Visio) Pin
sunil kumar verma12-Oct-09 1:45
membersunil kumar verma12-Oct-09 1:45 
GeneralCustom menu for visio 2007 Pin
Nithya R8-Jul-07 18:41
memberNithya R8-Jul-07 18:41 
GeneralRe: Custom menu for visio 2007 Pin
Shashidhar Rao Nellutla30-Jul-07 3:39
memberShashidhar Rao Nellutla30-Jul-07 3:39 
QuestionTime delay when running the code under VS2005 Pin
RealCosmo1234-Apr-07 4:55
memberRealCosmo1234-Apr-07 4:55 
GeneralProblem with Marshal.GetActiveObject in webservice Pin
subhashchandra12-Dec-05 1:35
membersubhashchandra12-Dec-05 1:35 
QuestionMultiple menu Items Pin
Dr Troll31-Aug-05 6:13
memberDr Troll31-Aug-05 6:13 
Generalone suggestion Pin
saritha_konda5-Jun-05 20:38
membersaritha_konda5-Jun-05 20:38 
GeneralCreating and Deleting Custom Menus in Visio using C# Pin
Jayashri30-Dec-04 7:00
memberJayashri30-Dec-04 7:00 
GeneralRe: Creating and Deleting Custom Menus in Visio using C# Pin
Armoghan Asif20-Jul-05 23:01
memberArmoghan Asif20-Jul-05 23:01 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 2 Jul 2004
Article Copyright 2004 by Shashidhar Rao Nellutla
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid