Paul Turner
Paul Turner

Reputation: 39615

How can a Custom Task Pane toggle visibility whilst keeping the UI responsive?

I'm trying to add a Custom Task Pane in an Excel Add-in which is intended to work similarly to the Pivot Tables pane.

The intention is that when a Table is selected the custom pane should appear and should disappear. To do this, I've created a custom task pane:

this._taskPane = Globals.AddIn.CustomTaskPanes.Add(
    new TableTaskPane(),
    "FooPane");
this._taskPane.DockPositionRestrict
    = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;

When the table is selected the pane is made visible, and when deselected the pane is hidden:

ListObject table = AddTable(); // Creates the table and populates with data.

table.Selected += range => this._taskPane.Visible = true;
table.Deselected += range => this._taskPane.Visible = false;

This achieves the effect of showing and hiding the pane, but unfortunately generates some lag in the UI, where the cursor "bounces" between the cells as the task pane transitions between visibility states.

This seems to be because the setter of the Visible property blocks until the Task Pane completes the transition. In Excel 2013, it slides out from the side of the window, which takes around 500ms.

I can't see any way to change this behaviour - I've tried scheduling the property-setting on the STA Thread, but it causes the same blocking. I'd be happy to change the Task Pane so that it just appears immediately without the transition (like the Pivot Table pane), but I don't see anything to make that happen either.

Am I doing this incorrectly? Is there a way to fix this with direct COM or some other subtly-hidden behaviour?

Upvotes: 15

Views: 799

Answers (2)

Neal
Neal

Reputation: 11

You should be able to set the width of the pane to zero either through the Pane API or failing that use the Windows API SetWindowPos. Then change the visibility. I don't use VSTO but know it can be done using the raw Office Pane objects.

Upvotes: 1

Josh Fierro
Josh Fierro

Reputation: 140

You can accomplish this (and even more performance improvements) by turning off silly windows animation features found here: Control Panel -> System and Security -> System -> Advanced Settings -> Performance Settings -> Visual Effects.

In this particular case, I believe you need to turn off this one:

  • Animate controls and elements inside windows.

But these are also great for speeding things up:

  • Fade or slide menus into view
  • Slide open combo boxes
  • Animate windows when minimizing and maximizing.

Upvotes: 0

Related Questions