Walkthrough: Putting a User Control in a Tool Window
This walkthrough demonstrates the process of adding a user control to a tool window implemented by a VSPackage.
A user control is a collection of Windows controls bound together in a single control. Adding a user control to a tool window is straightforward and all that is really needed is to 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#.
This walkthrough requires the Visual Studio SDK to be installed. The result of this walkthrough writes information to the experimental registry hive for Visual Studio 2008.
Creating the User Control Project
To create the ctlClockLib solution
Follow the procedure that is described in Walkthrough: Authoring a Composite Control with Visual C# to create the clock control. Do not create the alarm clock control.
The following procedures 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 procedures assume that you have named the clock control ctlClock as described in the walkthrough that was mentioned earlier.
To create the MyToolWindowUC VSPackage
On the File menu, point to New and select Project.
In the New Project dialog box, select Other Project Types and then select Extensibility from the Project types list.
In the Templates list, select Visual Studio Integration 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 Integration Package Wizard.
On the Select a Programming Language page, select Visual C# and accept the default 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 several moments, the Package Wizard finishes building the project. You obtain the "Creating project 'MyToolWindowPackageUC'…project creation successful" message on the status bar. Continue to add a user control to your project.
To add the ctlClockLib User Control
In Solution Explorer, right-click Solution 'MyToolWindowPackageUC', point to Add and select Existing Project.
In the Add Existing Project dialog box, open the ctlClockLib project and select the ctlClock.lib.csproj project file. Click OK. This enables the user control that you can use in the designer.
In Solution Explorer, right-click MyControl.cs 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's form.
In the designer, select the clock control that was just added and change the Anchor property to just be Top.
In the Solution Explorer, right-click the ctlClockLib project node and select Properties.
Select the Signing tab and check Sign the assembly. In the Choose a strong name key file text box, select <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 2008.
Press F5 to open an instance of Visual Studio 2008 in the experimental hive.
In the experimental Visual Studio 2008, open the View menu and select Other Windows and then select MyToolWindowUC. This displays your tool window with a running time display.