微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

单击CustomTaskPane上的按钮时如何更改功能区上的按钮标签在VSTO中添加Word

如何解决单击CustomTaskPane上的按钮时如何更改功能区上的按钮标签在VSTO中添加Word

我创建了两个按钮,状态按钮,在我的 Word附加功能认设置为“打开”,在我的 ChangeStatus 按钮中CustomTaskPane。

单击 CustomTaskPane 上的 ChangeStatus 按钮后,如何将状态按钮的标签从“打开”更改为“关闭”(在 Word附加功能上) / strong>。

image

代码功能区:

using System.Windows.Forms;
using Microsoft.Office.Tools.Ribbon;
using Office = Microsoft.Office.Core;
namespace TestWordAddIn
{
    public partial class Demo
    {
        private Detail myDetail;
        private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
        private void Demo_Load(object sender,RibbonUIEventArgs e)
        {
        }

        private void btnStatus_Click(object sender,RibbonControlEventArgs e)
        {
            // create new customtaskpane
            myDetail = new Detail();
            myCustomTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(myDetail,"Error List");
            myCustomTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
            myCustomTaskPane.Width = 380;
            myCustomTaskPane.Visible = true;
        }
    }
}

CustomTaskPane中的这段代码UserControl:

namespace TestWordAddIn
{
    public partial class Detail : UserControl
    {
        private Word.Application wApp = Globals.ThisAddIn.Application;
        public Detail()
        {
            InitializeComponent();
        }
        private void Detail_Load(object sender,EventArgs e)
        {
        }

        private void btnChangeStatus_Click(object sender,EventArgs e)
        {
            // Change status "Open" button to "Close" button in Ribbon when click ChangeStatus button at CustomTaskPane  
        }
    }
}

代码ThisAddIn.css:

namespace TestWordAddIn
{
    public partial class ThisAddIn
    {

        private void ThisAddIn_Startup(object sender,System.EventArgs e)
        {
    
        }

        private void ThisAddIn_Shutdown(object sender,System.EventArgs e)
        {
        }

        #region VSTO generated code
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}

解决方法

像这样:

Globals.Ribbons.Ribbon1.btn.label = ...

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。