locked
Dynamically change the CommandBarButton.Picture. (Vs2010 isolated shell)) RRS feed

  • Question

  • Hi,  

        I want to change image of CommandBarButton dynamically, the code is as following:

      CommandBarButton rmdCommandBarButton = GetRmdCommandButton();
                var picture = GetPicOfRmdCommandButton();
                if (rmdCommandBarButton != null && picture != null && rmdCommandBarButton.Picture != picture)
                    rmdCommandBarButton.Picture = (StdPicture) picture;

    When i call  the   "rmdCommandBarButton.Picture = (StdPicture) picture",The button icon in the toolbar work well, but  in the menu  item of Add or Remove Button,  the icon cannot display 

    Why? 

     
    Friday, March 28, 2014 5:34 AM

Answers

  • Hello Anthony,

    Thank you for visiting this forum!

    I guess that "Run Mode Change" button is your customize button. If not, please tell me where I can find it because I can not find it in my VS2012.

    What's more, please pay attention to the information below.

    Unfortunately assigning or editing icons to commands through Customize dialog is not possible in VS2010. It is one of the features got cut for lack of time. This is however something we'll consider adding back in next version.

    Until then, you can still set icons on your commands by using an add-in, then accessing the command through DTE.

    You can set CommandBarButton.Style to msoButtonIcon then set CommandBarButton.Picture with a stdole.IPicture. You can create IPicture objects using a helper class deriving from AxHost, e.g.

       public class ImageHelper : System.Windows.Forms.AxHost
    
       {
    
           // private constructor, needed for extending AxHost
    
           private ImageHelper (): base (null)
    
           {
    
           }
    
           /// <summary>
    
           /// Get an IPicture object from an Image.
    
           /// </summary>
    
           public static object GetIPictureFromImage (Image image)
    
           {
    
               return GetIPictureFromPicture(image);
    
           }
    
       };
    

    From this blog "Customizing Visual Studio 2010".

    Best regards,

    Sunny

    • Marked as answer by Anna Cc Friday, April 4, 2014 7:51 AM
    Monday, March 31, 2014 9:23 AM