locked
How to reenable CommandBarControl ? RRS feed

  • Question

  • Hi there,

    I'm trying to write a simple package for VS2010.
    I have a .vsct file where I define new Toolbar with some buttons.
    I can remove this button by calling Delete() method on CommandBarControl.


    Now the question is: how can I add the button back to the Toolbar?
    This seems to be possible to do from UI (by clicking on Toolbar Options - Add or Remove Buttons) but I cannot find any way to do it from code.
    I can call CommandBar .Reset() method, but this resets whole toolbar and I only want one button to be available again.

    Can someone help please?

    Wednesday, December 29, 2010 12:48 AM

Answers

  • What are you trying to accomplish exactly?  Deleting buttons is generally a customization, which should be done via the Tools->Customize dialog.  If you are trying to hide the button that is not supported on non-toolwindow toolbars as we don't want toolbar sizes constantly changing (it IS allowed for toolwindow toolbars).  Generally you add the item back via the DTE.Command object (which has a AddControl method), though be warned DTE has a fairly high memory cost and you shouldn't be forcing this on the user for something that they likely don't want/expect (like a non-toolwindow toolbar having disappearing buttons).

    Ryan

    • Marked as answer by Victor_Chen Wednesday, January 5, 2011 8:34 AM
    Wednesday, December 29, 2010 1:57 AM

All replies

  • What are you trying to accomplish exactly?  Deleting buttons is generally a customization, which should be done via the Tools->Customize dialog.  If you are trying to hide the button that is not supported on non-toolwindow toolbars as we don't want toolbar sizes constantly changing (it IS allowed for toolwindow toolbars).  Generally you add the item back via the DTE.Command object (which has a AddControl method), though be warned DTE has a fairly high memory cost and you shouldn't be forcing this on the user for something that they likely don't want/expect (like a non-toolwindow toolbar having disappearing buttons).

    Ryan

    • Marked as answer by Victor_Chen Wednesday, January 5, 2011 8:34 AM
    Wednesday, December 29, 2010 1:57 AM
  • Hi Lindau,

     

    Does Ryan's reply help?

     

    Best Regards,

    Ziwei Chen

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 5, 2011 8:34 AM
  • Thanks, that's exactly what I needed.

    I'm not going to change Toolbars dynamically during normal VS use, but rather trigger the change when user changes configuration options so it should be ok.

    Thanks again!

    Sunday, January 9, 2011 4:56 PM