Logo
BUG: Tooltip not set for add-in commands in Visual Studio 2005

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: January 2007   Microsoft Visual Studio 2005 SP1
       
Introduction

When you add a command in a VS 2005 add-in calling AddNamedCommand and specifying a tooltip text, buttons created from that command do not use that tooltip text. This did not happen in VS.NET 2002/2003.

Cause

This is a bug of Visual Studio 2005.

More Information

Steps to reproduce the problem:

  • Create a VS 2005 add-in in VB.NET with name "MyAddin1" and this code:
    Imports System
    Imports Microsoft.VisualStudio.CommandBars
    Imports Extensibility
    Imports EnvDTE
    Imports EnvDTE80
    
    Public Class Connect
       Implements IDTExtensibility2
       Implements IDTCommandTarget
    
       Private _applicationObject As DTE
       Private _addInInstance As AddIn
    
       Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, _
          ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    
          Dim colCommandBars As CommandBars
          Dim objCommandBar As CommandBar
          Dim objCommand As Command
    
          _applicationObject = CType(application, DTE)
          _addInInstance = CType(addInInst, AddIn)
    
          If connectMode = ext_ConnectMode.ext_cm_UISetup Then
    
             colCommandBars = CType(_applicationObject.CommandBars, CommandBars)
             objCommandBar = colCommandBars.Item("Standard")
    
             Try
                objCommand = _applicationObject.Commands.AddNamedCommand(_addInInstance, _
                "MyAddin1", "MyAddin1", "My tooltip", True, 59)
                objCommand.AddControl(objCommandBar, 1)
             Catch argumentException As System.ArgumentException
             End Try
    
          End If
    
       End Sub
    
       Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) _
          Implements IDTExtensibility2.OnDisconnection
       End Sub
    
       Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
       End Sub
    
       Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
       End Sub
    
       Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown
       End Sub
    
       Public Sub QueryStatus(ByVal commandName As String, ByVal neededText As vsCommandStatusTextWanted, _
          ByRef status As vsCommandStatus, ByRef commandText As Object) Implements IDTCommandTarget.QueryStatus
          
          If neededText = vsCommandStatusTextWanted.vsCommandStatusTextWantedNone Then
             If commandName = "MyAddin1.Connect.MyAddin1" Then
                status = CType(vsCommandStatus.vsCommandStatusEnabled + vsCommandStatus.vsCommandStatusSupported, vsCommandStatus)
             Else
                status = vsCommandStatus.vsCommandStatusUnsupported
             End If
          End If
       End Sub
    
       Public Sub Exec(ByVal commandName As String, ByVal executeOption As vsCommandExecOption, _
          ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
    
          handled = False
          If executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault Then
             If commandName = "MyAddin1.Connect.MyAddin1" Then
                handled = True
                Exit Sub
             End If
          End If
       End Sub
    
    End Class
  • Run the add-in project. A new IDE instance is loaded.
  • Load the add-in if it was not marked to load on startup when you created it with the wizard.
  • A button "MyAddin1" is added to the Standard toolbar.
  • When you put the mouse over the button, the tooltip is "MyAddin1" instead of "My tooltip" as we set when calling the AddNamedCommand method. This worked correctly in VS.NET 2002/2003.

Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


Top