• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

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
}
}

...全文
12 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nean 2003-05-24
gz...
回复
相关推荐
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2003-05-24 10:30
社区公告

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