Macro per creare Toolbar e shortcut nell'IDE

 

Questo codice crea Toolbar, può aggiunge alla Toolbar dei bottoni che richimano dei comandi qualunque (una altra Macro , un comando standard dell'IDE o un metodo di un Add-In) e può definire degli Shortcut  per qualsiasi comando.

Può essere usato dentro una Macro e negli Add-In di Visual Studio.

 

        Dim Answer As MsgBoxResult = MsgBox("Crea la toolbar dei PowerToys?", _
MsgBoxStyle.Question Or MsgBoxStyle.OkCancel) If Answer = MsgBoxResult.Ok Then Dim MyToolbar As CommandBars.CommandBar Const ToolbarName As String = "MyPowerToysToolbar"
' ' Delete the Toolbar if it already exists ' Try MyToolbar = DTE.CommandBars.Item(ToolbarName) MyToolbar.Delete() Catch e As ArgumentException End Try ' ' Create the Toolbar ' MyToolbar = DTE.Commands.AddCommandBar(ToolbarName _
, vsCommandBarType.vsCommandBarTypeToolbar) MyToolbar.Enabled = True MyToolbar.Visible = True
' ' Add comand buttons to the Toolbar ' AddCommandButtonToTheTollbar(MyToolbar _
, "Macros.Samples.Accessibility.IncreaseTextEditorFontSize" _
, "Font+", "Increase TextEditor font size") AddCommandButtonToTheTollbar(MyToolbar _
, "Macros.Samples.Accessibility.DecreaseTextEditorFontSize" _
, "Font-", "Decrease TextEditor font size") End If Dim Answer2 As MsgBoxResult = MsgBox("Attiva gli Shortcut ai comandi dei PowerToys?", _
MsgBoxStyle.Question Or MsgBoxStyle.OkCancel) If Answer2 = MsgBoxResult.Ok Then
' ' Define keyboard Shortcut fot the commands ' SetCommandShortcutKey("Macros.Samples.Accessibility.IncreaseTextEditorFontSize" _
, "Global::Alt+M") SetCommandShortcutKey("Macros.Samples.Accessibility.DecreaseTextEditorFontSize" _
, "Global::Alt+S") End If ---------------------------------------
Private Sub SetCommandShortcutKey(ByVal CommandName As String, ByVal Shortcut As String) Dim MacroCommand As Command = DTE.Commands.Item(CommandName) MacroCommand.Bindings = Shortcut End Sub Private Sub AddCommandButtonToTheTollbar(ByVal Toolbar As CommandBars.CommandBar_
, ByVal CommandName As String _
, ByVal CommandCaption As String _
, ByVal CommandTooltip As String) Dim MacroCommand As Command = DTE.Commands.Item(CommandName) Dim ToolbarButton As CommandBars.CommandBarButton = MacroCommand.AddControl(Toolbar) ToolbarButton.Visible = True ToolbarButton.Style = CommandBars.MsoButtonStyle.msoButtonCaption ToolbarButton.Caption = CommandCaption ToolbarButton.TooltipText = CommandTooltip End Sub

Print | posted @ sabato 15 marzo 2008 22:15

Comments have been closed on this topic.