excelvstocustomtaskpane

VSTO-Excel Custom Task Pane AutoResize based on Screen Resolution


I have a problem with my VSTO addin for excel. I tried creating custom task pane fot my addin. However, when I tried to deploy it on a screen with different resolution from the developer's monitor, the addin does not automatically fits the screen. Note: my clients have different screen resolution.

On my vsto project, i tried to create a custom user control, and attach it on the excel pane.

Please see my code below:

        private void btnDownload_Click(object sender, RibbonControlEventArgs e)
    {
        taskPaneView = new ucCusipAddPanel();

        if (myTaskPane == null)
        {
            myTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(taskPaneView, "My Custom Task Pane");
            myTaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
            myTaskPane.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
            myTaskPane.Visible = true;
            myTaskPane.Width = 303;
        }
        else
        {
            myTaskPane.Visible = true;
            taskPaneView.BringToFront();
            taskPaneView.Focus();
        }
    }

ucCusipAddPanel is the name of my user control.

This is how invoke my custom taskpane upon ribbon button click. I already set the AutoSize property to true of my user control however still the problem exists.

How could I resolve this? Thank you in advance.


Solution

  • You need to play with the AutoScaleMode of the myTaskPane object.

    I think the correct solution is to use: myTaskPane.AutoScaleMode = AutoScaleMode.Dpi;

    see MSDN