【问题标题】:How to change lable of button on Ribbon (Word Add In VSTO) when click button at CustomTaskPane单击自定义任务窗格中的按钮时如何更改功能区上按钮的标签(Word Add In VSTO)
【发布时间】:2020-10-08 07:41:36
【问题描述】:

我创建了两个按钮,Status 按钮在我的 Word 插件功能区ChangeStatus 按钮中默认为“打开”自定义任务窗格。

当点击 CustomTaskPaneChangeStatus 按钮时,如何将状态按钮的标签从“打开”更改为“关闭”(在 Word 插件功能区上) /strong>。

此代码功能区:

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

【问题讨论】:

标签: c# vsto ribbon word-addins customtaskpane


【解决方案1】:

像这样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    相关资源
    最近更新 更多