How to add additional tool windows to a Visual Studio Extension?

后端 未结 2 1866
渐次进展
渐次进展 2021-01-07 11:20

When creating an Extension for Visual Studio 2013 a tool window gets set up by default. However, I\'d like to have a second tool window and can\'t see how one is su

相关标签:
2条回答
  • 2021-01-07 11:59

    Well I just found a few things - so I'm gonna answer my own question so that other people having the same problem may take advantage of it:

    1. Set up your extension as in this tutorial but check "Tool Window"

    2. Create a new UserControl for the ToolWindow "ToolWindow2Control" and copy paste the contents of ToolWindowControl.xaml & ToolWindowControl.xaml.cs accordingly

    3. Add a class "ToolWindow2" and copy paste the contents from ToolWindow.cs. Change the GUID to a new one (Tools->Create GUID)

    4. In NameOfYourProject.vsct add the code for displaying a second entry in View->Other Windows by duplicating the Button found in the Buttons section. Change the ButtonText, the priority, the id of the Button and the id of the Icon.

    5. Add the id of the Button to the entries under Symbols on the bottom of the page. It should be a third entry under guidNameOfYourProjectCmdSet.

    6. Open PkgCmdID.cs (or PkgCmdIDList.cs) and add the id of the Button there as well, e.g.
      public const uint cmdidMyTool2 = 0x102;

    7. Add another icon to your project / resources. Then add another Bitmap entry in the Bitmaps section of NameOfYourProject.vsct with the GUID-id that you previously gave the Icon. Like so:
      <Bitmap guid="guidImages2" href="Images\test.ico" usedList="testIcon"/>
      And create another GuidSymbol entry in the Symbols section with a new GUID and a single IDSymbol entry which has the same name as the one you used in the usedList, like so:
      <GuidSymbol name="guidImages2" value="{7BC1F97F-2693-4186-91CC-A35AE95886CE}" > <IDSymbol name="testIcon" value="1" /> </GuidSymbol>

    8. Add this line to NameOfYourProjectPackage.cs:
      [ProvideToolWindow(typeof(ToolWindow2))]

    9. In NameOfYourProjectPackage.cs edit the Initialize method by copy-pasting the 3 lines under // Create the command for the tool window beneath it. In the first line use the id we gave in step #6 (cmdidMyTool2). In the 2nd line use a new MenuCommand Event handler ShowToolWindow2. And change the variable names.

    10. Create a new method ShowToolWindow2. Copy paste from the ShowToolWindow method and change the typeof in the first line to ToolWindow2

    This should be it. I hope I haven't forgot anything. You can then open the two windows under Views->Other Windows

    0 讨论(0)
  • 2021-01-07 12:00

    I have created a guide:

    HOWTO: Create a toolwindow with a ToolWindowPane class in a Visual Studio package http://www.visualstudioextensibility.com/2015/02/20/mz-tools-articles-series-howto-create-a-toolwindow-with-a-toolwindowpane-class-in-a-visual-studio-package/

    0 讨论(0)
提交回复
热议问题