Share via


Commands.AddNamedCommand, méthode

Crée une commande nommée qui est enregistrée par l'environnement et qui sera disponible au prochain démarrage de cet environnement, même si le complément n'est pas chargé au démarrage de l'environnement.

Espace de noms :  EnvDTE
Assembly :  EnvDTE (dans EnvDTE.dll)

Syntaxe

'Déclaration
Function AddNamedCommand ( _
    AddInInstance As AddIn, _
    Name As String, _
    ButtonText As String, _
    Tooltip As String, _
    MSOButton As Boolean, _
    Bitmap As Integer, _
    ByRef ContextUIGUIDs As Object(), _
    vsCommandDisabledFlagsValue As Integer _
) As Command
Command AddNamedCommand(
    AddIn AddInInstance,
    string Name,
    string ButtonText,
    string Tooltip,
    bool MSOButton,
    int Bitmap,
    ref Object[] ContextUIGUIDs,
    int vsCommandDisabledFlagsValue
)
Command^ AddNamedCommand(
    [InAttribute] AddIn^ AddInInstance, 
    [InAttribute] String^ Name, 
    [InAttribute] String^ ButtonText, 
    [InAttribute] String^ Tooltip, 
    [InAttribute] bool MSOButton, 
    [InAttribute] int Bitmap, 
    [InAttribute] array<Object^>^% ContextUIGUIDs, 
    [InAttribute] int vsCommandDisabledFlagsValue
)
abstract AddNamedCommand : 
        AddInInstance:AddIn * 
        Name:string * 
        ButtonText:string * 
        Tooltip:string * 
        MSOButton:bool * 
        Bitmap:int * 
        ContextUIGUIDs:Object[] byref * 
        vsCommandDisabledFlagsValue:int -> Command 
function AddNamedCommand(
    AddInInstance : AddIn, 
    Name : String, 
    ButtonText : String, 
    Tooltip : String, 
    MSOButton : boolean, 
    Bitmap : int, 
    ContextUIGUIDs : Object[], 
    vsCommandDisabledFlagsValue : int
) : Command

Paramètres

  • AddInInstance
    Type : EnvDTE.AddIn
    Obligatoire.L'objet AddIn ajoute la nouvelle commande.
  • Name
    Type : System.String
    Obligatoire.Forme courte du nom de votre nouvelle commande.AddNamedCommand utilise la préface Addins.Progid. pour créer un nom unique.
  • ButtonText
    Type : System.String
    Obligatoire.Nom à utiliser si la commande est liée à un bouton qui s'affiche sous la forme d'un nom et non d'une icône.
  • Tooltip
    Type : System.String
    Obligatoire.Texte qui s'affiche lorsqu'un utilisateur arrête le pointeur de la souris sur un contrôle lié à la nouvelle commande.
  • MSOButton
    Type : System.Boolean
    Obligatoire.Indique si l'image du bouton de la commande nommée est une image Office.True = bouton.Si MSOButton est False, le paramètre Bitmap correspond alors à l'ID d'une ressource bitmap 16x16 (et non d'une ressource icône) dans une DLL de ressource Visual C++ qui doit résider dans un dossier portant l'identificateur de paramètres régionaux de la langue (1033 pour l'anglais).
  • Bitmap
    Type : System.Int32
    Facultatif.ID d'une bitmap à afficher sur le bouton.
  • ContextUIGUIDs
    Type : array<System.Object[]%
    Facultatif.SafeArray d'identificateurs GUID qui détermine quels contextes d'environnement (mode débogage, mode design, etc.) affichent la commande.Consultez vsCommandDisabledFlags.

Valeur de retour

Type : EnvDTE.Command
Objet Command.

Notes

Les compléments peuvent changer ultérieurement le nom ButtonText en répondant à la méthode QueryStatus. Si le texte commence par "#", le reste de la chaîne est un entier qui représente un identificateur de ressource dans la DLL satellite enregistrée du complément.

Les paramètres ContextUIGUIDs et vsCommandStatusValue sont utilisés lorsque le complément n'est pas chargé et ne peut donc pas répondre à la méthode QueryStatus. Si ContextUIGUIDs est vide, la commande est activée jusqu'à ce que le complément soit chargé et puisse répondre à QueryStatus.

Le complément peut recevoir une notification d'invocation par l'intermédiaire de l'interface IDTCommandTarget. Un bouton peut être ajouté avec la méthode OnConnection de l'interface IDTExtensibility2

Exemples

' Macro code.
Imports Microsoft.VisualStudio.CommandBars
Sub AddControlExample()
   ' Before running, you must add a reference to the Office 
   ' typelib to gain access to the CommandBar object. Also, for this 
   ' example to work correctly, there should be an add-in available 
   ' in the Visual Studio environment.
   Dim cmds As Commands
   Dim cmdobj As Command
   Dim cmdbarobj As CommandBar
   Dim colAddins As AddIns

   ' Set references.
   colAddins = DTE.AddIns()
   cmds = DTE.Commands
   cmdobj = cmds.Item("File.NewFile")

   ' Create a toolbar and add the File.NewFile command to it.
   cmds.AddCommandBar("Mycmdbar", _
   vsCommandBarType.vsCommandBarTypeToolbar)
   MsgBox("Commandbar name: " & cmdbarobj.Name)
   cmdobj.AddControl(cmdbarobj)
   cmds.AddNamedCommand(colAddins.Item(1), "MyCommand", _
   "Button Text", "Some tooltip", True)
End Sub

Sécurité .NET Framework

Voir aussi

Référence

Commands Interface

EnvDTE, espace de noms