How to change the Caption of the Command on the toolbar from a Macro in VS2010?

别说谁变了你拦得住时间么 提交于 2019-12-04 19:32:26

I've implemented it:

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!