3logy
3logy

Reputation: 2712

How to disable resizing and close button of a Custom Task Pane?

How can I prevent an Office Custom Task Pane for resizing, so that it's only and always have the dimensions and can't be closing with the "close" button.

myCustomTaskPane.Height = 500;
myCustomTaskPane.Width = 500;

Upvotes: 3

Views: 5171

Answers (4)

jreichert
jreichert

Reputation: 1566

For the "Must not be closed"-Part of the problem you can maybe use this one instead of a timer:

private void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
{
  if (!myCustomTaskPane.Visible)
  {
    //Start new thread to make the CTP visible again since changing the
    //visibility directly in this event handler is prohibited by Excel.
    new Thread(() =>
    {
      myCustomTaskPane.Visible = true;
    }).Start();
  }
}

Hope it helps, Jörg

Upvotes: 0

Larry G. Wapnitsky
Larry G. Wapnitsky

Reputation: 1246

Where _tp is a reference to your task pane (not the CustomTaskPane container), _ctp is the CustomTaskPane container, iw is the InspectorWrapperDictionary:

 void _tpvals_VisibleChanged(object sender, System.EventArgs e)
        {
            _tp.tmr.Start();
        }

And, in your task pane code:

public Timer tmr;

        public taskpane()
        {
            InitializeComponent();

            tmr = new Timer() { Interval = 500 };
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Enabled = true;
            tmr.Stop();
        }


void tmr_Tick(object sender, EventArgs e)
        {
            if (iw == null)
                setVars();

            if (_tp.lv_AttachmentList.Items.Count > 0)
                _ctp.Visible = true;

            tmr.Stop();
        }

setvars() is a command to pull in the proper iw and set the references to _tp and _ctp

Upvotes: 1

3logy
3logy

Reputation: 2712

I find a Solution for this One :

void NormalizeSize(object sender, EventArgs e)
    {
        if (this.taskPane.Height > 558 || this.taskPane.Width > 718)
        {
            this.taskPane.Height = 558;
            this.taskPane.Width = 718;
        }
        else{
            this.taskPane.Width = 718;
            this.taskPane.Height = 558;
        }
    }        

Upvotes: 0

DarinH
DarinH

Reputation: 4879

As far as the resize, just monitor your task pane's resize event and reset the size. However you might consider +why+ you'd want to do that. If there's a minimum necessary size for your taskpane, it might make more sense to restrict the minimum. and if the contents are resizable, maybe they should be.

You might also override the OnLayout method. That will often work better.

For the Close button, I think you'd want to intercept the "VisibleChanged" event and make the pane visible if it's been hidden. As I recall, taskpanes are not actually "closed" per se, but just set invisible.

Upvotes: 3

Related Questions