共用方式為


Commands 介面

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 類型會公開下列成員。

屬性

  名稱 描述
公用屬性 Count 取得值,指出 Commands 集合中物件的數目。
公用屬性 DTE 取得最上層的擴充性物件。
公用屬性 Parent 取得 Commands 集合的直接上層父物件。

回頁首

方法

  名稱 描述
公用方法 Add 基礎架構。 僅限 Microsoft 內部使用。
公用方法 AddCommandBar 建立一個會儲存並且可在下次環境啟動時使用的命令列。
公用方法 AddNamedCommand 建立一個由環境所儲存並可在下次環境啟動時使用的具名命令,即使該增益集於環境啟動時並未載入也一樣。
公用方法 CommandInfo 傳回與指定 Microsoft.VisualStudio.CommandBars.CommandBar 控制項關聯的命令 GUID 和 ID。
公用方法 GetEnumerator 傳回 Commands 集合中項目的列舉程式。
公用方法 Item 傳回已建立索引的 Command 物件。
公用方法 Raise 執行指定命令。
公用方法 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

請參閱

參考

EnvDTE 命名空間