1

我想在自定义任务窗格中操作控件,例如将文本设置为自定义任务窗格中的文本框。如何更改下面的代码?

1.ribbon.cs,ribbon中有一个togglebutton,我可以通过点击togglebutton在自定义任务窗格中将文本设置为文本框吗?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft;
using Microsoft.Office.Tools.Ribbon;
using System.Windows.Forms;

namespace XML1
{
    public partial class RibbonXML1
    {
        private void RibbonXML1_Load(object sender, RibbonUIEventArgs e)
        {

        }
        private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
        {
            Share.ctp1.Visible = this.toggleButton1.Checked;
            if (this.toggleButton1.Checked)
            { 
                toggleButton1.Label = "Hide"; 
            }
            else
            {
                toggleButton1.Label = "Show";
            }

        }
    }
}

自定义任务窗格中的用户控件有一个文本框。

  1. 这是 thisAddin.cs 显示或隐藏自定义任务窗格的代码。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml.Linq;
    using Word = Microsoft.Office.Interop.Word;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools.Word;
    
    namespace XML1
    {
        public partial class ThisAddIn
        {
            UserControl1 uc1;
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
            uc1 = new UserControl1();
            Share.ctp1 = this.CustomTaskPanes.Add(uc1, "acReport");
            Share.ctp1.Visible = true;
            Share.ctp1.VisibleChanged += new EventHandler(ctp1_visibleChanged);
            Share.ctp1.DockPositionChanged += new EventHandler(ctp1_DockPositionChanged);
    
    
        }
        private void ctp1_visibleChanged(object sender, System.EventArgs e)
        {
    
            RibbonXML1 ribbon = Globals.Ribbons.GetRibbon<RibbonXML1>(); 
            ribbon.toggleButton1.Checked = Share.ctp1.Visible;
        }
        private void ctp1_DockPositionChanged(object sender, System.EventArgs e)
        {
            Globals.ThisAddIn.Application.StatusBar = Share.ctp1.DockPosition.ToString();
        }
    
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }
    
        #region VSTO generate code
    
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
    
        #endregion
    }
    

    }

4

1 回答 1

1

在下面找到答案链接; 如何在 CustomTaskPane VSTO C# 中的 UserControl 中公开列表框。将以下代码附加到 ThisAddIn_Startup 中,然后:

foreach (Control rtbControl in uc1.Controls)
            {

                if (rtbControl is RichTextBox & rtbControl.Name == "richTextBox1")
                {
                    rtbControl.Text = "Hello";
                }
            }
于 2017-12-26T10:16:44.937 回答