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.

Prerequisites

To follow this walkthrough, you must install the Visual Studio 2013 SDK. For more information, see Visual Studio Software Development Kit (SDK).

Locations for the Visual Studio Package Project Template

The Visual Studio Package project template can be found in three different locations in the New Project dialog:

  1. Under Visual Basic Extensibility. The default language of the project is Visual Basic.

  2. Under C# Extensibility. The default language of the project is C#.

  3. Under Other Project Types Extensibility. The default language of the project is C++

Creating the User Control Project

To create the ctlClockLib solution

  1. 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.

  2. Close the ctlClockLib solution.

  3. Continue to "Creating a Tool Window VSPackage".

    Note

    The following steps assume that you have named the clock control ctlClock.

Creating a Tool Window VSPackage

To create the MyToolWindowUC VSPackage

  1. On the File menu, point to New, and then click Project.

  2. In the New Project dialog box, select Other Project Types and then select Extensibility on the Project types list.

  3. In the Templates list, select Visual Studio Package.

  4. Type the name of your project; for example, MyToolWindowPackageUC (the rest of this walkthrough assumes that name). Select a destination for the project.

  5. Click OK to open the Visual Studio Package Template.

  6. On the Select a Programming Language page, select Visual C# or Visual Basic and accept the default setting for the key file. Click Next.

  7. On the Select VSPackage Options page, select Tool Window. Click Next.

  8. On the Tool Window Options page, set the Window Name to MyToolWindowUC and set the Command ID to cmdidMyToolWindowUC. Click Finish.

  9. After the message "Creating project 'MyToolWindowPackageUC'…project creation successful" is displayed on the status bar, you can add a user control to your project.

Adding the User Control

To add the ctlClockLib User Control

  1. In Solution Explorer, right-click the solution 'MyToolWindowPackageUC', point to Add, and then click Existing Project.

  2. 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.

  3. 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.

  4. 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.

  5. In the designer, select the clock control that was just added and change the Anchor property to just be Top.

  6. In Solution Explorer, right-click the ctlClockLib project node and then click Properties.

  7. 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.

  8. Compile the program and make sure there are no errors. This step registers the VSPackage and its tool window with Visual Studio.

  9. Press F5 to open an instance of Visual Studio in the experimental hive.

  10. 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.

See Also

Tasks

Walkthrough: Authoring a Composite Control with Visual C#