【问题标题】:How to change the Caption of the Command on the toolbar from a Macro in VS2010?如何在VS2010的宏中更改工具栏上命令的标题?
【发布时间】:2011-10-27 22:35:05
【问题描述】:

我正在通过宏访问工具栏上的命令:

Dim name As String = "Macros.MyMacros.MyMacros.ToggleExceptions"
Dim cmd As EnvDTE.Command = DTE.Commands.Item(name)

现在如何更改工具栏上命令的标题?它似乎没有必要的属性。我需要把它转换成别的东西吗?

【问题讨论】:

  • 该宏实际上并不访问工具栏上的命令。我认为 DTE.CommandBars 将是一个起点。

标签: vb.net visual-studio-2010 macros vs-extensibility


【解决方案1】:

我已经实现了:

Private Sub Main()
    Const BAR_NAME As String = "MenuBar"
    Const CTL_NAME = "Foo"

    ChangeCommandCaption(BAR_NAME, CTL_NAME, "Bar")
End Sub

Private Sub ChangeCommandCaption(ByVal cmdBarName As String, ByVal ctlName As String, ByVal caption As String)
    Dim bars As Microsoft.VisualStudio.CommandBars.CommandBars

    bars = DirectCast(DTE.CommandBars, Microsoft.VisualStudio.CommandBars.CommandBars)
    If bars Is DBNull.Value Then Exit Sub

    Dim menuBar As CommandBar = bars.Item(cmdBarName)
    If menuBar Is DBNull.Value Then Exit Sub

    Dim cmdBarCtl As CommandBarControl

    Try
        cmdBarCtl = menuBar.Controls.Item(ctlName)
        If cmdBarCtl Is DBNull.Value Then Exit Sub
    Catch ex As Exception
        Exit Sub
    End Try

    cmdBarCtl.Caption = caption
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多