包含环境中的所有命令(以 Command 对象的形式)。
命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)
语法
声明
<GuidAttribute("E6B96CAC-B8C7-40AE-B705-5C81878C4A9E")> _
Public Interface Commands _
    Inherits IEnumerable
[GuidAttribute("E6B96CAC-B8C7-40AE-B705-5C81878C4A9E")]
public interface Commands : IEnumerable
[GuidAttribute(L"E6B96CAC-B8C7-40AE-B705-5C81878C4A9E")]
public interface class Commands : IEnumerable
[<GuidAttribute("E6B96CAC-B8C7-40AE-B705-5C81878C4A9E")>]
type Commands =  
    interface
        interface IEnumerable
    end
public interface Commands extends IEnumerable
Commands 类型公开以下成员。
属性
| 名称 | 说明 | |
|---|---|---|
| .gif) | Count | 获取一个值,该值指示 Commands 集合中对象的数目。 | 
| .gif) | DTE | 获取顶级扩展性对象。 | 
| .gif) | Parent | 获取 Commands 集合的直接父对象。 | 
页首
方法
| 名称 | 说明 | |
|---|---|---|
| .gif) | Add | 基础结构。仅 Microsoft 内部。 | 
| .gif) | AddCommandBar | 创建一个命令栏,该命令栏被保存并且在下次启动环境时可用。 | 
| .gif) | AddNamedCommand | 创建命名命令,该命令由环境保存,并且在下次环境启动时(无论是否加载外接程序)可用。 | 
| .gif) | CommandInfo | 返回与给定 Microsoft.VisualStudio.CommandBars.CommandBar 控件关联的命令 GUID 和 ID。 | 
| .gif) | GetEnumerator() | 返回一个循环访问集合的枚举数。 (继承自 IEnumerable。) | 
| .gif) | GetEnumerator() | 返回有关 Commands 集合中项的枚举数。 | 
| .gif) | Item | 返回已索引的 Command 对象。 | 
| .gif) | Raise | 执行指定的命令。 | 
| .gif) | RemoveCommandBar | 移除用 AddCommandBar 方法创建的命令栏。 | 
页首
示例
Imports Microsoft.VisualStudio.CommandBars
Sub CommandsExample()
   ' Before running, you must add a reference to the Office 
   ' typelib to gain access to the CommandBar object.
   Dim cmds As Commands
   Dim cmdobj As Command
   Dim customin, customout As Object
   Dim cmdbarobj As CommandBar
   Dim colAddins As AddIns
   ' Set references.
   colAddins = DTE.AddIns()
   cmds = DTE.Commands
   cmdobj = cmds.Item("File.NewFile")
   ' Execute the File.NewFile command.
   cmds.Raise(cmdobj.Guid, cmdobj.ID, customin, customout)
   ' Create a toolbar and add the File.NewFile command to it.
   cmdobj = cmds.Item("File.NewFile")
   cmdbarobj = cmds.AddCommandBar("Mycmdbar", _
     vsCommandBarType.vsCommandBarTypeToolbar)
   cmdobj.AddControl(cmdbarobj)
   ' Show the command bar and its button.
   cmdbarobj.Visible = True
End Sub