Help: 用C#给Visio做Add-in

John_Cash 2003-05-24 10:30:13
照着 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
}
}

...全文
93 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nean 2003-05-24
  • 打赏
  • 举报
回复
gz...

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧