Walkthrough: Putting a User Control in a Tool Window
This walkthrough demonstrates how to add a user control to a tool window that is implemented by a VSPackage.
A user control is a collection of Windows controls bound together in one control. To add a user control to a tool window, all you really have to do is obtain the user control to appear in the Toolbox. The user control that is used in this walkthrough is the clock control developed in Walkthrough: Authoring a Composite Control with Visual C# or Walkthrough: Authoring a Composite Control with Visual Basic.
The Visual Studio Package project template can be found in three different locations in the New Project dialog:
Under Visual Basic Extensibility. The default language of the project is Visual Basic.
Under C# Extensibility. The default language of the project is C#.
Under Other Project Types Extensibility. The default language of the project is C++
Creating the User Control Project
To create the ctlClockLib solution
Follow the steps in Walkthrough: Authoring a Composite Control with Visual C# or Walkthrough: Authoring a Composite Control with Visual Basic to create the clock control. Do not create the alarm clock control.
The following steps assume that only the clock control is created, not the alarm clock control.
Close the ctlClockLib solution.
Continue to "Creating a Tool Window VSPackage".
The following steps assume that you have named the clock control ctlClock.
To create the MyToolWindowUC VSPackage
On the File menu, point to New, and then click Project.
In the New Project dialog box, select Other Project Types and then select Extensibility on the Project types list.
In the Templates list, select Visual Studio Package.
Type the name of your project; for example, MyToolWindowPackageUC (the rest of this walkthrough assumes that name). Select a destination for the project.
Click OK to open the Visual Studio Package Template.
On the Select a Programming Language page, select Visual C# or Visual Basic and accept the default setting for the key file. Click Next.
On the Select VSPackage Options page, select Tool Window. Click Next.
On the Tool Window Options page, set the Window Name to MyToolWindowUC and set the Command ID to cmdidMyToolWindowUC. Click Finish.
After the message "Creating project 'MyToolWindowPackageUC'…project creation successful" is displayed on the status bar, you can add a user control to your project.
To add the ctlClockLib User Control
In Solution Explorer, right-click the solution 'MyToolWindowPackageUC', point to Add, and then click Existing Project.
In the Add Existing Project dialog box, open the ctlClockLib project and select the ctlClock.lib.csproj or ctlClock.lib.vbproj project file. Click OK. This enables the user control that you can use in the designer.
In Solution Explorer, right-click MyControl.cs or MyControl.vb and select View Designer. This opens the forms designer that shows the generated control for the tool window.
Open the Toolbox, find the section labeled ctlClockLib Components and double-click the ctlClock control in that section to add the control to the form. As soon as you hide the Toolbox, you should see a time display in your tool window form.
In the designer, select the clock control that was just added and change the Anchor property to just be Top.
In Solution Explorer, right-click the ctlClockLib project node and then click Properties.
On the Signing tab, select Sign the assembly. In the Choose a strong name key file box, click <browse> and navigate to the key.snk file in the MyToolWindowPackageUC project folder.
Compile the program and make sure there are no errors. This step registers the VSPackage and its tool window with Visual Studio.
Press F5 to open an instance of Visual Studio in the experimental hive.
In the experimental Visual Studio, on the View menu, point to Other Windows and then click MyToolWindowUC. This displays your tool window, which has a running time display.