Creating and Deleting Custom Menus in Visio

Introduction

There are several ways to handle the menus in Microsoft Visio application but are no events generated when the user click the menu.The best way to handle the menus and menu event handling is through CommandBars.Most of the sites i gone never find a solution.Some of the forums mentioned the idea how to implement.I needed something quicker to find the solution then i got through commandBars.Hope this article will help you in all aspects in handling the menu Bar.

With this article not only to handle the menus in Microsoft.Visio we can handle the menus in all microsoft applications ex: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.

Code:
This demo contains CustomMenu class which will take care of Setting the custom menus and deleting the custom menu from 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 following statement will work

Visio.UIObject uiObject = this.visioApplication.BuiltInMenus; After adding the menu to the menu bar it should set to standard menu bar of the visio application with the following statement.

this.visioApplication.ActiveWindow.Document.SetCustomMenus(uiObject); To get the standard CommandBars of the visio application following statement will execute.

commandBars=(Microsoft.Office.Core.CommandBars) 
this.visioApplication.CommandBars;
Note:

*This demo requires visio application should run and it requires a default drawing should be opened.

Conclusion:
CommandBars can be used for a lot of things, creating Menu Bars,ToolBars,etc.I feel CommandBar is the best way to handle the Micosoft 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.

Download Source

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值