Question

I have an Excel Add-In that has 2 buttons, the second of which I would like to be hidden when the Add-in is loaded. Here is my code:

public void OnStartupComplete(ref System.Array custom)
{
    object omissing = System.Reflection.Missing.Value;                

    CommandBarButton Button1 = (CommandBarButton)g_PLCToolBarInstance.Controls.Add(1, omissing, omissing, omissing, omissing);
    Button1 .Visible = true;
    Button1 .Enabled = true;
    Button1 .Caption = "Button1";                
    Button1 .Style = MsoButtonStyle.msoButtonIcon;
    Button1 .Picture = PictureDispConverter.ToIPictureDisp(OneIco);

    CommandBarButton Button2 = (CommandBarButton)g_PLCToolBarInstance.Controls.Add(1, omissing, omissing, omissing, omissing);
    Button2 .Visible = false;
    Button2 .Enabled = false;
    Button2 .Caption = "Button2";
    Button2 .Style = MsoButtonStyle.msoButtonIcon;
    Button2 .Picture = PictureDispConverter.ToIPictureDisp(TwoIco);

    ....
}

Problem is the second button gets drawn, then removed (instead of being hidden from the start), leaving a ghost image of the TwoIco on the Toolbar Options dropdown ...

Bad

instead of ...

Good

Any Ideas please?!

Was it helpful?

Solution

I have an old add-in that created buttons in OnStartupComplete, and looking through the code, the only substantive difference in mine was I set the .Visible = false last, after setting the Caption, Style, and Picture properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top