更新:2007 年 11 月
返回 Commands 集合中的一个 Command 对象。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
Function Item ( _
index As Object, _
ID As Integer _
) As Command
用法
Dim instance As Commands
Dim index As Object
Dim ID As Integer
Dim returnValue As Command
returnValue = instance(index, ID)
Command Item(
Object index,
int ID
)
Command^ Item(
[InAttribute] Object^ index,
[InAttribute] int ID
)
function Item(
index : Object,
ID : int
) : Command
参数
- index
类型:System.Object
ID
类型:System.Int32可选。指定的命令集中的命令 ID。
返回值
一个 Command 对象。
备注
如果 index 是绝对索引(Long 型),则它只对从命令 1 到命令 n 上的迭代有意义。您无法保存命令的绝对索引和以后使用它访问该命令。
如果 index 是 GUID 字符串,则它指示一个命令集,并且您必须提供 ID 参数来标识该集中的命令。
如果提供了 ID 参数且第一个参数为字符串,则 index 参数必须为标识命令集的 GUID 字符串。如果 index 为字符串且没有 ID 参数,则 index 必须为命令的全名。如果 index 是 Long 型,则 ID 被忽略。
示例
' Macro code.
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
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。