如何通过单击功能区按钮将文本设置到自定义任务窗格中的文本框?

问题描述 投票:0回答:1

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

1.ribbon.cs,功能区中有一个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";
            }

        }
    }
}

自定义任务窗格中的Usercontrol具有文本框。

  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 } }
c# user-controls customtaskpane
1个回答
0
投票

找到下面的答案链接; How to Expose Listbox in UserControl in CustomTaskPane VSTO C#。将以下代码附加到ThisAddIn_Startup中,然后确定:

foreach (Control rtbControl in uc1.Controls)
            {

                if (rtbControl is RichTextBox & rtbControl.Name == "richTextBox1")
                {
                    rtbControl.Text = "Hello";
                }
            }
© www.soinside.com 2019 - 2024. All rights reserved.