回 帖 发 新 帖 刷新版面

主题:要在word中加一个按钮

要在word中加一个按钮,但是debug时打开word,却显示不出按钮,是怎么回事呢?

回复列表 (共2个回复)

沙发

你在程序里面新建或者获取application对象 注意设置它的属性为true
启动后打开应该就有了
当然你要让他加载你的那段代码

板凳

谢谢楼上! 不知道应该怎么设置你说的属性? 
我要做一个按钮,点击就可插入图片
我刚学,这个程序是照menu做的,耽误你时间,麻烦你帮我看看好么? 真是太谢谢了!!!
部分程序:
public void OnStartupComplete(ref System.Array custom)
        {
              MessageBox.Show(wordApp.ActiveDocument.Name);
            
             CommandBars oCommandBars;
            CommandBar oStandardBar;

            try
            {
                oCommandBars = (CommandBars)wordApp.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, wordApp, null);
            }
            catch (Exception)
            {
                object oActiveExplorer;
                oActiveExplorer = wordApp.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, wordApp, null);
                oCommandBars = (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
            }
            try
            {
                oStandardBar = oCommandBars["AK47"];
            }
            catch (Exception)
            {
                oStandardBar = oCommandBars.Add("AK47", MsoBarPosition.msoBarFloating, null, null);
            }
            oStandardBar.Visible = true;
            try
            {
                InsertPictureButton = (CommandBarButton)oStandardBar.Controls["插入图片"];
            }
            catch (Exception)
            {
                object omissing = System.Reflection.Missing.Value;
                InsertPictureButton = (CommandBarButton)oStandardBar.Controls.Add(1, omissing, omissing, omissing, omissing);
                InsertPictureButton.Caption = "插入图片";
                InsertPictureButton.Style = MsoButtonStyle.msoButtonIcon;
            }
            InsertPictureButton.FaceId = 6578;
            InsertPictureButton.Tag = "插入图片";
            InsertPictureButton.Visible = true;
            InsertPictureButton.Click+=new
            _CommandBarButtonEvents_ClickEventHandler(InsertPictureButton_Click);

我来回复

您尚未登录,请登录后再回复。点此登录或注册