1

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?!

Community
  • 1
  • 1
Tizz
  • 820
  • 1
  • 15
  • 31
  • Hi Tizz,I have a problem with setting Picture property of my CommandBarButton.Could you please give me PictureDispConverter class to me? Thanks in advance... – M_Mogharrabi Mar 09 '13 at 08:40

1 Answers1

2

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.

CtrlDot
  • 3,102
  • 3
  • 25
  • 32
  • Well that worked! Thanks so much! One would think if you set the visible to false BEFORE you set the icon, the icon wouldn't show at all, not the other way around. Whatever! Thanks again! – Tizz Mar 09 '12 at 19:17