Hide Task Pane by Default

Add-in Express™ Support Service
That's what is more important than anything else

Hide Task Pane by Default
 
Jeremy McClanathan




Posts: 20
Joined: 2017-02-09
Hello,
I have an advance word task pane that I would like to be hidden by default. I found the post linked below and based on that tried the following code:

        private void ADXWordTaskPaneSingleDoc_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e)
        {
            this.Visible = false;
        }


The code above works to hide the task pane by default, but also seems to keep it hidden all the time. To show the task pane I have a show/hide checkbox on a ribbon. The code above works to hide the task pane by default, but the checkbox stops working when the code above in used. How can I hide the task pane at startup, but still allow the task pane visibility to be turned on/off with the ribbon checkbox?

ADD-IN EXPRESS
Jeremy
Posted 07 Oct, 2018 01:05:14 Top
Andrei Smolin


Add-in Express team


Posts: 16223
Joined: 2006-05-11
Hello Jeremy,

private bool visibility = false;

private void ADXWordTaskPaneSingleDoc_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e) 
{ 
    this.Visible = visibility; 
} 

public new void Show()
{
    visibility = true;
    base.Show();
    visibility = false;
}


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 Oct, 2018 04:38:22 Top
Jeremy McClanathan




Posts: 20
Joined: 2017-02-09
I get the same issue when I use the code above. The task pane does not show initially, but the checkbox does not work (can't get the task pane to show at all). If I change the initial value of visiblity to
private bool visibility = true; 
, then the checkbox works to show/hide the task pane, but the task pane is initially shown at startup.
Jeremy
Posted 15 Oct, 2018 00:47:18 Top
Andrei Smolin


Add-in Express team


Posts: 16223
Joined: 2006-05-11
Hello Jeremy,

I see. Try this variant. Note that you will need to polish it in order to work with several windows; in this case, you will need to have a dictionary of booleans; the key should be the window name. The idea is to use a boolean corresponding to the given window; you will also need to control how Word creates/closes windows in order to control the dictionary.


        public AddinModule()
        {
            Application.EnableVisualStyles();
            InitializeComponent();
            LetPaneShow = false;
            // Please add any initialization code to the AddinInitialize event handler
        }
...
        public bool LetPaneShow { get; private set; }

        private void adxRibbonButton1_PropertyChanging(object sender, ADXRibbonPropertyChangingEventArgs e)
        {
            if (e.PropertyType == ADXRibbonControlPropertyType.Caption)
            {
                AddinExpress.WD.ADXWordTaskPane pane = this.adxWordTaskPanesCollectionItem1.CurrentTaskPaneInstance;
                if (pane != null)
                {
                    if (pane.Visible)
                    {
                        System.Diagnostics.Debug.WriteLine("!!! pane Visible");
                        e.Value = "Hide pane";
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("!!! pane NOT Visible");
                        e.Value = "Show pane";
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("!!! pane is NULL!");
                }
            }
        }

        private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed)
        {
            System.Diagnostics.Debug.WriteLine("!!! adxRibbonButton1_OnClick");
            AddinExpress.WD.ADXWordTaskPane pane = this.adxWordTaskPanesCollectionItem1.CurrentTaskPaneInstance;
            if (pane != null)
            {
                if (pane.Visible)
                {
                    pane.Hide();
                    adxRibbonButton1.Invalidate();
                }
                else
                {
                    LetPaneShow = true;
                    pane.Show();
                    adxRibbonButton1.Invalidate();
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("!!! pane is NULL!");
            }
            System.Diagnostics.Debug.WriteLine("!!! adxRibbonButton1_OnClick. end");
        }


    public partial class ADXWordTaskPane1: AddinExpress.WD.ADXWordTaskPane
    {
        public ADXWordTaskPane1()
        {
            InitializeComponent();
        }

        private void ADXWordTaskPane1_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e)
        {
            this.Visible = MyAddin184.AddinModule.CurrentInstance.LetPaneShow;
            System.Diagnostics.Debug.WriteLine("!!! ADXWordTaskPane1_ADXBeforeTaskPaneShow. this.Visible=" + this.Visible.ToString());
        }
    }


Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Oct, 2018 07:03:46 Top
Jeremy McClanathan




Posts: 20
Joined: 2017-02-09
Thank you Belarus. It turns out the reason why your first suggested code wasn't working for me is because your show() method is not getting called in my code, the windows form show() method is getting called instead. I placed your show() method in the task pane class, then called it from the ribbon checkbox on_click method using the following code:


                if (adxRibbonCheckBox1.Pressed == true)
                {
                    adxWordTaskPanesCollectionItem2.CurrentTaskPaneInstance.Show();
                }
                else
                {
                    adxWordTaskPanesCollectionItem2.CurrentTaskPaneInstance.Visible = false;
                }


Should the show() method be placed somewhere else, or should it be called in a different way?
Jeremy
Posted 16 Oct, 2018 00:14:47 Top
Andrei Smolin


Add-in Express team


Posts: 16223
Joined: 2006-05-11
Hello Jeremy,

I don't understand your question. You can call ADXOlForm.Show from where your logic requires this.

Does the code sample above work for you?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 16 Oct, 2018 03:40:29 Top