1
votes

I want to manipulate the controls in a custom task pane,like set text to a textbox which is in a custom task pane.How to change the codes below?

1.ribbon.cs ,There is a togglebutton in ribbon , can I set text to textbox in the custom task pane by click the 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 in the custom task pane has a textbox.

  1. here is the code for thisAddin.cs to show or hide the custom task pane.

    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
    }
    

    }

1

1 Answers

1
votes

Found the answer link below; How to Expose Listbox in UserControl in CustomTaskPane VSTO C#. Append codes below into ThisAddIn_Startup ,ok then:

foreach (Control rtbControl in uc1.Controls)
            {

                if (rtbControl is RichTextBox & rtbControl.Name == "richTextBox1")
                {
                    rtbControl.Text = "Hello";
                }
            }