none
I have a question about customtaskpane in MS WORD RRS feed

  • Question

  • Hi,

    I'm developing a customtaskpane in MS WORD.

    There was a problem in the course of development. 

    When I run two programs, The customtaskpane can only be seen from one place. Like the picture above.

    Is there any way to solve this problem?

    ThisAddin.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Word = Microsoft.Office.Interop.Word;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools.Word;
    using System.Diagnostics;
    
    namespace WordAddIn2
    {
        public partial class ThisAddIn
        {
            private Microsoft.Office.Tools.CustomTaskPane pane;
            private CellTaskPane ctrl = new CellTaskPane();
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                pane = CustomTaskPanes.Add(ctrl, "Custom Sheet");
                pane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
                pane.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
                pane.Visible = false;
                pane.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
                ctrl.SetName("test");
            }
    
            private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
            {
                Debug.WriteLine("pane.Visible : " + pane.Visible);
                Globals.Ribbons.Ribbon1.toggleButton1.Checked = pane.Visible;
            }
    
            public Microsoft.Office.Tools.CustomTaskPane TaskPane
            {
                get
                {
                    return pane;
                }
            }
    
            public CellTaskPane MyContainer
            {
                get
                {
                    return ctrl;
                }
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
    
            #endregion
        }
    }

    Ribbon1.cs

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    
    namespace WordAddIn2
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
            private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
            {
                Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
                Debug.WriteLine(Globals.ThisAddIn.TaskPane.Visible);
            }
    
        }
    }
    

    cellTaskPane.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace WordAddIn2
    {
        public class CellTaskPane : System.Windows.Forms.UserControl
        {
            public System.Windows.Forms.TextBox test;
    
            public CellTaskPane()
            {
                InitializeComponent();
            }
    
            public void InitializeComponent()
            {
                test = new System.Windows.Forms.TextBox();
                test.Location = new System.Drawing.Point(120, 8);
                test.Size = new System.Drawing.Size(232, 20);
                test.TabIndex = 0;
                Controls.AddRange(new System.Windows.Forms.Control[] { test });
                Size = new System.Drawing.Size(375, 150);
            }
    
            public void SetName(string text)
            {
                test.Text = text;
            }
    
            public string GetName()
            {
                return test.Text;
            }
        }
    }
    

    Wednesday, November 28, 2018 7:24 AM

Answers

  • Hi nrisnh,

    I tested this project again, I found some problems.

    With Word it's important to note that a new document window is usually NOT equivalent to a new instance of the Word application. Word is pseudo-SDI, meaning it opens a separate window for each document, rather than multiple documents sharing the same application window. But there's only the one application instance.

    Please see the following screenshot:

    For more information, please refer to the following link:

    word addin ribbon instance when multiple word documents are opened

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.



    • Edited by Lina-MSFT Saturday, December 1, 2018 12:49 AM
    • Marked as answer by nrisnh Monday, December 3, 2018 5:02 AM
    Friday, November 30, 2018 9:10 AM

All replies

  • Hi nrishnh,

    The following screenshot is my test result:

    I suggest you to clean the project, and then restart both projects. 

    Or you can do it again according to the steps in this document.

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    • Edited by Lina-MSFT Thursday, November 29, 2018 2:45 AM
    Thursday, November 29, 2018 2:35 AM
  • Hi nrishnh,

    The following screenshot is my test result:

    I suggest you to clean the project, and then restart both projects. 

    Or you can do it again according to the steps in this document.

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    thank you for answering me.

    I followed the information you sent me.

    but, There is nothing different in action.

    If you don't mind, can I see your source code?


    Thursday, November 29, 2018 5:43 AM
  • Hi nrisnh,

    -- ThisAddin.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Word = Microsoft.Office.Interop.Word;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools.Word;
    
    namespace WordAddIn1
    {
        public partial class ThisAddIn
        {
            private TaskPaneControl taskPaneControl1;
            private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                taskPaneControl1 = new TaskPaneControl();
                taskPaneValue = this.CustomTaskPanes.Add(
                    taskPaneControl1, "MyCustomTaskPane");
                taskPaneValue.VisibleChanged +=
                    new EventHandler(taskPaneValue_VisibleChanged);
            }
    
            private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
            {
                Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked =
                    taskPaneValue.Visible;
            }
    
            public Microsoft.Office.Tools.CustomTaskPane TaskPane
            {
                get
                {
                    return taskPaneValue;
                }
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }

    --ManageTaskPaneRibbon.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    
    namespace WordAddIn1
    {
        public partial class ManageTaskPaneRibbon
        {
            private void ManageTaskPaneRibbon_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
            {
                Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
            }
        }
    }

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    • Edited by Lina-MSFT Thursday, November 29, 2018 5:56 AM
    Thursday, November 29, 2018 5:56 AM
  • Hi nrisnh,

    -- ThisAddin.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Word = Microsoft.Office.Interop.Word;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools.Word;
    
    namespace WordAddIn1
    {
        public partial class ThisAddIn
        {
            private TaskPaneControl taskPaneControl1;
            private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                taskPaneControl1 = new TaskPaneControl();
                taskPaneValue = this.CustomTaskPanes.Add(
                    taskPaneControl1, "MyCustomTaskPane");
                taskPaneValue.VisibleChanged +=
                    new EventHandler(taskPaneValue_VisibleChanged);
            }
    
            private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
            {
                Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked =
                    taskPaneValue.Visible;
            }
    
            public Microsoft.Office.Tools.CustomTaskPane TaskPane
            {
                get
                {
                    return taskPaneValue;
                }
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            
            #endregion
        }
    }

    --ManageTaskPaneRibbon.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    
    namespace WordAddIn1
    {
        public partial class ManageTaskPaneRibbon
        {
            private void ManageTaskPaneRibbon_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
            {
                Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
            }
        }
    }

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    It's the same code, but I don't know why not. T_T
    Friday, November 30, 2018 4:12 AM
  • Hi nrisnh,

    Have you tested the code on other machines? 

    May I know your OS and Word version?

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    • Marked as answer by nrisnh Friday, November 30, 2018 5:32 AM
    • Unmarked as answer by nrisnh Friday, November 30, 2018 5:32 AM
    Friday, November 30, 2018 5:29 AM
  • Hi nrisnh,

    Have you tested the code on other machines? 

    May I know your OS and Word version?

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    There is no other machine to test.

    Windows7 and Microsoft Office Professional Plus 2016.

    I develop using a visual studio Community2017.

    and My test method is to run two MS Word after installing addin. It was not tested with debugging mode.
    • Edited by nrisnh Friday, November 30, 2018 6:56 AM
    Friday, November 30, 2018 5:37 AM
  • Hi nrisnh,

    I tested this project again, I found some problems.

    With Word it's important to note that a new document window is usually NOT equivalent to a new instance of the Word application. Word is pseudo-SDI, meaning it opens a separate window for each document, rather than multiple documents sharing the same application window. But there's only the one application instance.

    Please see the following screenshot:

    For more information, please refer to the following link:

    word addin ribbon instance when multiple word documents are opened

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.



    • Edited by Lina-MSFT Saturday, December 1, 2018 12:49 AM
    • Marked as answer by nrisnh Monday, December 3, 2018 5:02 AM
    Friday, November 30, 2018 9:10 AM
  • Thank you very much for answering.
    That's the answer I wanted.
    Monday, December 3, 2018 5:03 AM