问题
Recently I wrote an outlook add-in which has a ribbon.xml file for an extra ribbon, context menu's, etc. I also added an extra panel docked on the right of my window.
Now I've begun some research as on how to create add-ins for Visio. The ribbon.xml is practically the same, so that's not a problem at all. However, I can't seem to find any way to add a custom panel when a Visio document is opened.
So far I have this in Visio to know if a document is opened/created/changed:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
MessageBox.Show("Visio Add-In V1");
Globals.ThisAddIn.Application.DocumentChanged += new Visio.EApplication_DocumentChangedEventHandler(docChanged);
Globals.ThisAddIn.Application.DocumentOpened += new Visio.EApplication_DocumentOpenedEventHandler(docChanged);
Globals.ThisAddIn.Application.DocumentCreated += new Visio.EApplication_DocumentCreatedEventHandler(docChanged);
}
private void docChanged(Visio.Document doc)
{
MessageBox.Show("Document loaded");
}
In outlook I would do this to add a custom panel (simplified):
MyPanel ctrl = new MyPanel();
Microsoft.Office.Tools.CustomTaskPane ctp = Globals.ThisAddIn.CustomTaskPanes.Add(ctrl, title);
ctp.Visible = true;
ctp.Width = 300;
ctp.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
Now how would I be able to do this in a Visio 2013 Add-In?
Edit:
Unfortunately this makes me think it's not possible: http://msdn.microsoft.com/en-us/library/vstudio/bf08984t.aspx
Edit2:
The following answer should work: Are Task Panes Available in Visio VSTO?
However I can't seem to find a way to get a docked panel on my main window. Here is what I tried:
Globals.ThisAddIn.Application.Windows.Add("testpanel", VisWindowStates.visWSDockedLeft, VisWinTypes.visStencilAddon, null, null, null, 300);
This adds the window as if it were a new drawing...
Edit3:
Visio throws a COM exception on this saying I have an invalid window type.
Application.Windows.Add("testpanel", VisWindowStates.visWSDockedRight, VisWinTypes.visAnchorBarAddon, null, null, 300);
回答1:
You can use Anchor Bars in Visio, not Task Panes If you download the Visio SDK and look in the Codes Samples Library, you will find Anchor Bar Usage under User Interface.
For completeness, you may wish to review this MSDN article Windows.Add Method (Visio) - http://msdn.microsoft.com/en-us/library/office/ff767674.aspx
来源:https://stackoverflow.com/questions/15518156/how-can-you-add-a-custom-panel-in-a-visio-2013-add-in