Commands2.Item(Object, Int32) 方法

定义

返回集合的索引成员。

EnvDTE::Command Item(winrt::Windows::Foundation::IInspectable const & index, int ID = -1);
[System.Runtime.InteropServices.DispId(0)]
public EnvDTE.Command Item (object index, int ID = -1);
[<System.Runtime.InteropServices.DispId(0)>]
abstract member Item : obj * int -> EnvDTE.Command
Public Function Item (index As Object, Optional ID As Integer = -1) As Command

参数

index
Object

必需。 绝对索引、GUID 字符串或命令的全名。

ID
Int32

可选。 指定命令集中的命令 ID。

返回

Command

Command 对象。

实现

属性

示例

Sub ItemExample()  
   Dim cmds As Commands  
   Dim cmd As Command  

   ' Set references to the Commands collection and the File.NewFile   
   ' command.  
   cmds = DTE.Commands  
   cmd = cmds.Item("File.NewFile")  

   ' Assign the command (File.NewFile) globally to the F2 key.  
   ' Because you cannot programmatically change the default keyboard  
   ' mapping scheme settings, you must first make a copy of the Default   
   ' Settings for the Keyboard Mapping Scheme.  
   cmd.Bindings = "Global::f2"  
End Sub  

注解

如果 index 是一个绝对索引 (Long) ,则仅对从1到 n 的命令进行循环访问是有意义的。 不能保存命令的绝对索引,以后再使用它来访问该命令。

如果 index 是 GUID 字符串,则它指示命令集,并且必须提供 ID 参数以标识集中的命令。

如果提供了 ID 参数并且第一个参数是字符串,则 index 参数必须是标识命令集的 GUID 字符串。 如果 index 是一个字符串并且没有 ID 参数,则 index 必须是命令的完整名称。 如果 index 是长时间,则 ID 将被忽略。

适用于