Help: 用C#给Visio做Add-in
照着 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTipsTricksBuildingMicrosoftOfficeAdd-insWithVisualCNETVisualBasicNET.asp 里的说明,一步一步走下来,可是
public void insertText_Click(Microsoft.Office.Core.CommandBarButton
barButton, ref bool someBool);只有在Visio启动页“选择绘图类型”中可以调用到,之后,当打开一个文件进行绘图时,再怎么按工具栏上新加的button都不起作用了。
请各位高人指点。
----
几个主要的方法如下:
private void SetApplicationFields(object application)
{
vapp=application as Visio.Application;
if(vapp==null){
// error
}
}
// add toolbar
private Microsoft.Office.Core.CommandBar AddVisioToolbar(
Visio.Application vso, string toolbarName)
{
Microsoft.Office.Core.CommandBar toolBar = null;
try
{
// Create a command bar for the add-in
object missing = System.Reflection.Missing.Value;
toolBar = (Microsoft.Office.Core.CommandBar)
((Microsoft.Office.Core.CommandBars)vapp.CommandBars).Add(toolbarName,
Microsoft.Office.Core.MsoBarPosition.msoBarTop,
missing, true);
toolBar.Visible = true;
return toolBar;
}
catch
{
// Add exception handling here.
return null;
}
}
// add button
private
Microsoft.Office.Core.CommandBarButton
MakeANewButton(
Microsoft.Office.Core.CommandBar commandBar, string caption,
int faceID,
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler
clickHandler )
{
object missing = System.Reflection.Missing.Value;
try
{
Microsoft.Office.Core.CommandBarButton newButton;
newButton = (Microsoft.Office.Core.CommandBarButton)
commandBar.Controls.Add(
Microsoft.Office.Core.MsoControlType.msoControlButton,
missing, missing, missing, missing);
newButton.Caption = caption;
newButton.FaceId = faceID;
//newButton.Click+=null;
newButton.Click += clickHandler;
return newButton;
}
catch (System.Exception )
{
// Add code here to handle the exception.
return null;
}
}
// event call back
public void insertText_Click(Microsoft.Office.Core.CommandBarButton
barButton, ref bool someBool)
{
if (vapp != null) {
object obj=vapp.ActivePage;
if(obj==null){//error
}
// do something
}
}