Share via


How to: Change the Default Icon for an Add-in

You can change the default icon that Visual Studio associates with the menu item for an add-in that you create by using the Visual Studio Add-in project type.

When you create an add-in by using the Visual Studio Add-in project type, you have the option of creating a user interface (UI) for the add-in by checking the "Would you like to create a command bar UI for your add-in?" box. To find the Visual Studio Add-in project type, expand Other Project Types, and then click Extensibility Projects in the New Project dialog box.

The template creates a Tools menu item that causes your add-in to load when a user clicks it. The menu item has a default smiley-face icon next to the command, which you can change by using one of two methods.

One way is to simply change the default icon index number (which is 59) to the number of another standard icon in the Microsoft.VisualStudio.CommandBars assembly, which contains nearly 3,000 icons. A second option is to define a custom bitmap, such as a company logo or custom icon, place it as a resource in a satellite DLL, and then change your add-in's code to point to that new bitmap. The former method is quicker and easier, but you are limited to the icons in Microsoft.VisualStudio.CommandBars. The latter method involves a bit more work, but you can use the exact icon you want.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and ExportSettings on the Tools menu. For more information, see Visual Studio Settings.

To change the default icon to another standard icon

  1. Open a solution created by the Add-in Wizard.

  2. In the OnConnection event, look for the following line:

    command = commands.AddNamedCommand2(_addInInstance, _
      "MyAddin1", "MyAddin1",  _
      "Executes the command for MyAddin1", True, 59, Nothing, _
      CType(vsCommandStatus.vsCommandStatusSupported, _
       Integer) + 
       CType(vsCommandStatus.vsCommandStatusEnabled, _
       Integer), vsCommandStyle.vsCommandStylePictAndText, _
       vsCommandControlType.vsCommandControlTypeButton)
    
    Command command = commands.AddNamedCommand2(_addInInstance, 
    "MyAddin1", "MyAddin1", "Executes the command for MyAddin1", 
    true, 59, ref contextGUIDS, (int)vsCommandStatus.
    vsCommandStatusSupported+(int)vsCommandStatus.
    vsCommandStatusEnabled, (int)vsCommandStyle.
    vsCommandStylePictAndText, vsCommandControlType
    .vsCommandControlTypeButton);
    

    Notice the number, 59, in the AddNamedCommand2 call. This is the index of the default icon, a smiley-face. To change to a different standard icon, change this number. For example, to change the icon to a red star, change 59 to 6743. When you run your add-in, the command appears on the Tools menu next to a red star icon.

    For information about how to find the ID numbers for standard icons, see Listing Button Faces in the Command Bar for the Microsoft Office System on the MSDN Web site.

    If you cannot find an appropriate icon in the Microsoft.VisualStudio.CommandBars library, you can use a custom bitmap for the add-in's command icon. The bitmap is contained as a resource in a satellite DLL. For more information, see How to: Display a Custom Icon on the Add-in Button. After creating the satellite DLL resource, you then point AddNamedCommand2 to the custom icon.

    Note

    The Visual Studio Automation Samples site has a downloadable example project demonstrating how to do this in Visual Basic and Visual C#. Click the "Custom Bitmap Add-in" link.

See Also

Tasks

How to: Control Add-ins with the Add-In Manager

How to: Create an Add-In

Walkthrough: Creating a Wizard

Concepts

Add-in Registration

Automation Object Model Chart

Reference

Visual Studio Commands and Switches

Other Resources

Creating Add-ins and Wizards

Change History

Date

History

Reason

December 2008

Replaced broken link about how to find FaceIDs.

Customer feedback.