请教微软专家, Office XP PIA 的问题

ZengXi 2002-10-17 04:54:05
以下是我的代码,我的问题是,如何给myButton3加上图标,请微软专家给我个例子
private void button1_Click(object sender, System.EventArgs e)
{
Word.Application wdApp = new Word.Application();

wdApp.Visible = true;
Thread.Sleep(3000);
bool IsExisted = false;
object SaveChanges = Missing.Value;
object originalFormat = Missing.Value;
object routeDocument = Missing.Value;
object optional = Missing.Value;
object visible = true;

DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
FileInfo[] fi = di.GetFiles("example3.doc");
if (fi.Length <= 0)
{
di = new DirectoryInfo(Environment.CurrentDirectory+@"\..\..");
fi = di.GetFiles("本是同根生.doc");
}
object fileName = fi[0].FullName;

//打开指定目录下的Word文件
Word._Document doc = wdApp.Documents.Open2000(ref fileName, ref optional,
ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional,
ref optional, ref optional, ref optional,
ref visible);

//打开Word中的修订痕迹功能
doc.TrackRevisions = true;
doc.ShowRevisions = true;
doc.PrintRevisions = true;

//doc.Activate();

object BarName = "Word文件修改痕迹保留";

Microsoft.Office.Core.CommandBar myBar;
IEnumerator Objs = doc.CommandBars.GetEnumerator();
while (Objs.MoveNext()==true)
{
Microsoft.Office.Core.CommandBar tempBar = (Microsoft.Office.Core.CommandBar)Objs.Current;
//MessageBox.Show(tempBar.Name);
if(tempBar.Name.Trim()==BarName.ToString())
{
IsExisted = true;
}
}


if(!IsExisted)
{
myBar = doc.CommandBars.Add(BarName, optional, optional, optional);
doc.CommandBars.ActiveMenuBar.Visible = true;
myBar.Visible = true;
myBar.Position = Microsoft.Office.Core.MsoBarPosition.msoBarTop;
Microsoft.Office.Core.CommandBarControl myButton, myCombo;
object Id = "2222";
object Id2 ="2221";
object IconId = 1000;
object Parameter="test";
myButton = myBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Id, optional, optional, optional);
myCombo = myBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Id2, optional, optional, optional);

//Microsoft.Office.Core.MsoControlType.msoControlButton myButton = (Microsoft.Office.Core.MsoControlType.msoControlButton)myBar.Controls[0];
//myBar.Controls[1].pa
//myButton


Microsoft.Office.Core.CommandBarButton myButton3 = (Microsoft.Office.Core.CommandBarButton)myButton;
myButton3.TooltipText = "提示信息";
myButton3.DescriptionText = "这是我添加的按钮";
myButton3.Style = Core.MsoButtonStyle.msoButtonIcon;
Bitmap myBMP = new Bitmap(this.imageList1.Images[0]);
//myBMP.BackgroundImage = this.imageList1.Images[0];
//PictureBox a = new PictureBox();

//System.Drawing.Icon myIcon = new System.Drawing.Icon(".\app.ico");
Graphics b = Graphics.FromImage(myBMP);
IntPtr hdc = b.GetHdc();

doc.
myButton3.FaceId = myIcon.Id;

myButton3.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.myButton_Click);
}

//领导最后确认修改,并保存文档,去掉修订的痕迹
//doc.AcceptAllRevisionsShown();
//doc.AcceptAllRevisions();


//object first = 0;
//object last = doc.Characters.Count;

//doc.Range(ref first, ref last).Select();

//wdApp.Quit(ref SaveChanges, ref originalFormat, ref routeDocument);


}

private void myButton_Click(Microsoft.Office.Core.CommandBarButton sender, ref bool b)
{
//Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler result = new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler();
MessageBox.Show("执行click");
}
...全文
97 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZengXi 2002-10-24
  • 打赏
  • 举报
回复
......
ZengXi 2002-10-19
  • 打赏
  • 举报
回复
55555,还是没有人知道么???
我再顶
nakrul 2002-10-18
  • 打赏
  • 举报
回复
就是,连help文件都没有
ZengXi 2002-10-18
  • 打赏
  • 举报
回复
没有人知道,ms的专家呢?麻烦了.
开发包连个例子都不带,不像ms的作风啊
ZengXi 2002-10-17
  • 打赏
  • 举报
回复
自己up一下

110,534

社区成员

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

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

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