共用方式為


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

Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions. For more information about upgrading, see FAQ: Converting Add-ins to VSPackage Extensions.

You can change the icon that is associated with the menu command for an add-in that you created by using the Visual Studio Add-in project type. To find the Add-in project type, in the New Project dialog box, expand Other Project Types and then click Extensibility Projects.

When you create an add-in by using the Add-in project type, the Add-in Wizard lets you add a user interface (UI) for the add-in by selecting the Would you like to create a command bar UI for your add-in? check box.

The template creates a command on the Tools menu that opens your add-in. By default, adjacent to the command is a smiley-face icon. You can change the icon by using one of the following methods:

  • Change the icon index number (which is 59 for the default icon) to the number of another icon in the Microsoft.VisualStudio.CommandBars assembly. The assembly contains almost 3,000 icons.

  • Define a custom bitmap, for example, a company logo, compile it in a satellite DLL as a resource, and then change your add-in code to point to the new bitmap.

The first method is quicker, but you can only use the icons in Microsoft.VisualStudio.CommandBars. The second method lets you use any icon.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Customizing Development Settings in Visual Studio.

To change the current icon to another icon

  1. Open a solution that was created by using the Add-in project type.

  2. In the project file, in the OnConnection method, 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 current icon. 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 together with 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.

  3. If you cannot find an appropriate icon in the Microsoft.VisualStudio.CommandBars library, you can use a custom bitmap. Compile the bitmap in a satellite DLL as a resource. For more information, see How to: Display a Custom Icon on the Add-In Button. After you create the satellite DLL resource, point to it in AddNamedCommand2.

See Also

Tasks

How to: Control Add-Ins By Using the Add-In Manager

How to: Create an Add-In

Walkthrough: Creating a Wizard

Reference

PAVE Visual Studio Commands and Switches

Concepts

Add-In Registration

Automation Object Model Chart

Other Resources

Creating Add-ins and Wizards