Как добавить панель инструментов в надстройку Visual Studio? - PullRequest
3 голосов
/ 09 ноября 2010

Я создал новый проект надстройки Visual Studio. Мой проект может добавлять команды в меню Visual Stuido. Этот код создан мастером. Как добавить свою настраиваемую панель инструментов в Visual Studio?

1 Ответ

7 голосов
/ 09 ноября 2010

Ознакомьтесь с руководством по MZ-Tools .

Кнопка на "стандартной" панели инструментов

 commandBars = DirectCast(<dte instance>.CommandBars, CommandBars)
 standardCommandBar = commandBars.Item(VS_STANDARD_COMMANDBAR_NAME)

 ' Add a button to the built-in "Standard" toolbar
 myStandardCommandBarButton = DirectCast(myCommand.AddControl(standardCommandBar, _
 standardCommandBar.Controls.Count + 1), CommandBarButton)

 ' Change some button properties
 myStandardCommandBarButton.Caption = MY_COMMAND_CAPTION
 myStandardCommandBarButton.Style = MsoButtonStyle.msoButtonIcon ' It could be also        msoButtonIconAndCaption
 myStandardCommandBarButton.BeginGroup = True ' Separator line above button

Новая панель инструментов

     commandBars = DirectCast(<dte instance>.CommandBars, CommandBars)

     ' Add a new toolbar 
     myTemporaryToolbar = commandBars.Add(MY_TEMPORARY_TOOLBAR_CAPTION, _
        MsoBarPosition.msoBarTop, System.Type.Missing, True)

     ' Add a new button on that toolbar
     myToolBarButton = DirectCast(myCommand.AddControl(myTemporaryToolbar, _
        myTemporaryToolbar.Controls.Count + 1), CommandBarButton)

     ' Change some button properties
     myToolBarButton.Caption = MY_COMMAND_CAPTION
     myToolBarButton.Style = MsoButtonStyle.msoButtonIconAndCaption ' It could be also msoButtonIcon

     ' Make visible the toolbar
     myTemporaryToolbar.Visible = True
...