Black rectangle appears for a brief when my Custom Taskpane is visible on the Excel

Srivastava, Amit 0 Reputation points
2024-11-16T15:03:48.1766667+00:00

I am creating a COM-based Excel Add-In using the Excel VSTO project in Visual Studio 2022 using .Net Framework 4.8. In that, I am building a Custom TaskPane and adding a simple UserControl to it in ThisAddIn.cs like below

public CustomTaskPane TaskPane { get; private set; }

 private void ThisAddIn_Startup(object sender, System.EventArgs e)

 {

     Application.WorkbookActivate += Application_WorkbookActivate;

 }

 private void Application_WorkbookActivate(Excel.Workbook wb)

 {

     var control = new UserControl();

     TaskPane = CustomTaskPanes.Add(control, "Test");

     TaskPane.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;

     TaskPane.Width = 600;

     TaskPane.Visible = false;

 }

And disposing of it like below

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)

{

    TaskPane.Dispose();

}

I am making my TaskPane Visible on ToggleButton click in the Ribbon1.cs like below

public void ToggleButton_Click(IRibbonControl control, bool isPressed)

{

     var taskPane = Globals.ThisAddIn.TaskPane;

     taskPane.Visible = true;

}

Below is my Ribbon1.xml <?xml version="1.0" encoding="UTF-8"?>

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">

  <ribbon>

    <tabs>

      <tab id="TabAddIns" label="Test">

        <group id="MyGroup" label="My Group">

          <box id="box1" boxStyle="horizontal">

            <toggleButton id="btnWelcome" onAction="ToggleButton_Click" label="Welcome" />

          </box>

        </group>

      </tab>

    </tabs>

  </ribbon>

</customUI>

When I run my AddIn in Excel and click the Welcome button, a black rectangle appears for a brief on my TaskPane at the TaskPane title area. It also appears when I close the Excel.

I cannot figure out the problem and how to resolve it. Can anyone please help me?

Thanks

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,012 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.