Sunil kumar verma

Hello,

i want to overload the VISIO File>Open menu so that i can show my custom open dialog when user click it. Please let me know how i can implement it using C#.

Thanks and Regards,

Sunil



Re: Visual Studio Tools for Office Override the VISIO menu

Ji Zhou – MSFT

No, you cannot overwrite the action of the built-in button. My thought is hide the system open button, and create your own buttons with the same name and picture. Then define you event handle to the new created buttons.

The following codes work fine in my side. I test in a Visio Add In. Hope it helps!

Code Block

Office.CommandBarButton btnOpen1 = null;

Office.CommandBarButton btnOpen2 = null;

Office.CommandBars commandBars = null;

Office.CommandBarPopup fileMenu = null;

private void ThisAddIn_Startup(object sender, System.EventArgs e)

{

commandBars = this.Application.CommandBars as Office.CommandBars;

commandBars["Standard"].Controls["Open"].Visible = false;

((Office.CommandBarButton)commandBars["Standard"].Controls["Open"]).CopyFace();

btnOpen1 = commandBars["Standard"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 2, true) as Office.CommandBarButton;

btnOpen1.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon;

btnOpen1.Caption = "MyOpen";

btnOpen1.PasteFace();

btnOpen1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

fileMenu = commandBars["Menu Bar"].Controls["&File"] as Office.CommandBarPopup;

fileMenu.Controls["&Open..."].Visible = false;

btnOpen2 = fileMenu.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 2, true) as Office.CommandBarButton;

btnOpen2.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;

btnOpen2.Caption = "&Open...";

btnOpen2.PasteFace();

btnOpen2.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

}

void btnOpen_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)

{

new Form().Show();

}

Thanks

Ji






Re: Visual Studio Tools for Office Override the VISIO menu

Sunil Verma

Hi Ji,

Thanks for your reply.

This code is not working on my place.I am caling OverideOpenMenu() function from following function as:

public void OnConnection(

object application,

Extensibility.ext_ConnectMode connectMode,

object addInInst,

ref System.Array custom)

{

OverideOpenMenu()

}

private void OverideOpenMenu()

{

commandBars = (Microsoft.Office.Core.CommandBars)vsoApplication.CommandBars;

commandBars["Standard"].Controls["Open"].Visible = false;

((Microsoft.Office.Core.CommandBarButton)commandBars["Standard"].Controls["Open"]).CopyFace();

btnOpen1 = commandBars["Standard"].Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 2, true) as Microsoft.Office.Core.CommandBarButton;

btnOpen1.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon;

btnOpen1.Caption = "MyOpen";

btnOpen1.PasteFace();

btnOpen1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

fileMenu = commandBars["Menu Bar"].Controls["&File"] as Microsoft.Office.Core.CommandBarPopup;

fileMenu.Controls["&Open..."].Visible = false;

btnOpen2 = fileMenu.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 2, true) as Microsoft.Office.Core.CommandBarButton;

btnOpen2.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;

btnOpen2.Caption = "&Open1234...";

btnOpen2.PasteFace();

btnOpen2.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

}

in my code on "missing" argument in fileMenu.Controls.Add function i was getting error so i made it Type.Missing.I debug this code every variable is populating properly but the open menu caption did not change.on clicking that menu item control did not come on

btnOpen_Click. function.

please let me know where i am doing the mistake

Thanks and Regards,

Sunil





Re: Visual Studio Tools for Office Override the VISIO menu

Ji Zhou – MSFT

This is a Shared Add In. The right place for it should be Office Automation News Group and Visio General News Group.

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.office.developer.com.add_ins&lang=en&cr=US

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.visio.developer&lang=en&cr=US

However, I create a Shared Add In and use the codes above. Everything works fine. I paste the codes as follows:

Code Block

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)

{

vsoApplication = application as Microsoft.Office.Interop.Visio.Application;

addInInstance = addInInst;

OverideOpenMenu();

}

private void OverideOpenMenu()

{

commandBars = (Microsoft.Office.Core.CommandBars)vsoApplication.CommandBars;

commandBars["Standard"].Controls["Open"].Visible = false;

((Microsoft.Office.Core.CommandBarButton)commandBars["Standard"].Controls["Open"]).CopyFace();

btnOpen1 = commandBars["Standard"].Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 2, true) as Microsoft.Office.Core.CommandBarButton;

btnOpen1.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon;

btnOpen1.Caption = "MyOpen";

btnOpen1.PasteFace();

btnOpen1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

fileMenu = commandBars["Menu Bar"].Controls["&File"] as Microsoft.Office.Core.CommandBarPopup;

fileMenu.Controls["&Open..."].Visible = false;

btnOpen2 = fileMenu.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 2, true) as Microsoft.Office.Core.CommandBarButton;

btnOpen2.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;

btnOpen2.Caption = "&Open1234...";

btnOpen2.PasteFace();

btnOpen2.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnOpen_Click);

}

void btnOpen_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)

{

new Form().Show();

}

And at last of the Class, we should have these variables’ declaration:

Code Block

private Microsoft.Office.Interop.Visio.Application vsoApplication;

private object addInInstance;

private Office.CommandBarButton btnOpen1 = null;

private Office.CommandBarButton btnOpen2 = null;

private Office.CommandBars commandBars = null;

private Office.CommandBarPopup fileMenu = null;

I didn’t see you initial the vsoApplication in OnConnection. Maybe that is the issue!

Thanks

Ji






Re: Visual Studio Tools for Office Override the VISIO menu

Sunil Verma

Hi Ji,

Thanks a lot. it start working.