マクロから、ツールバーにあるコマンドにアクセスしています。
Dim name As String = "Macros.MyMacros.MyMacros.ToggleExceptions"
Dim cmd As EnvDTE.Command = DTE.Commands.Item(name)
ツールバーのコマンドのキャプションを変更するにはどうすればよいですか?必要な特性がないようです。他の何かにキャストする必要がありますか?
マクロから、ツールバーにあるコマンドにアクセスしています。
Dim name As String = "Macros.MyMacros.MyMacros.ToggleExceptions"
Dim cmd As EnvDTE.Command = DTE.Commands.Item(name)
ツールバーのコマンドのキャプションを変更するにはどうすればよいですか?必要な特性がないようです。他の何かにキャストする必要がありますか?
私はそれを実装しました:
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