How to: Use a VSPackage Tool Window to Display a Help Topic

After you create a tool window, you might want to display help topics that apply to the user interface (UI). A VSPackage tool window can QueryService SVsHelp service to obtain the Help2 object to display Help information.

The following procedure explains how to use the Visual Studio Integration Package wizard to create a VSPackage tool window and add functionality to it to display Help content by using an F1 keyword.

To create a tool window VSPackage

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

    The New Project dialog box appears.

  2. In the Project types pane, expand Other Project Types, and then click Extensibility.

  3. In the Templates pane, click Visual Studio Integration Package.

  4. In the Name box, type MyHelpToolWin.

  5. In the Location box, type a path or accept the default folder, (<drive>:\Documents and Settings\<User Name>\My Documents\Visual Studio Projects), and then click OK.

  6. On the Select a Programming Language page, select Visual C#. For the key-file entry, accept the default setting, and click Next.

  7. On the Basic VSPackage Information page, accept the default values and click Next.

  8. On the Select VSPackage Options page, select Tool Window and click Next.

  9. On the Tool Window Options page, accept the default values and click Finish.

    The MyHelpToolWin solution is created and appears in the Solution Explorer.

  10. On the Build menu, click Build Solution to verify the solution builds without errors.

To add Help2 functionality to the tool window

  1. In Solution Explorer, click MyHelpToolWin.

  2. On the Project menu, click Add Reference.

  3. In the Add Reference dialog box, click the NET tab, select Microsoft.VisualStudio.VSHelp and Microsoft.VisualStudio.VSHelp80 from the Component Name list, and click then OK.

  4. In Solution Explorer, click MyControl.cs.

  5. On the View menu, click Designer if the user control is not already in Design view.

  6. Double-click the button control with the text, Click Me!

  7. Replace the code in the button1_Click method with the code below:

    private void button1_Click(object sender, System.EventArgs e)
    {
        Microsoft.VisualStudio.VSHelp80.Help2 help2;
       // Obtain the Help2 object from SVsHelp service.
        help2 =  
    (Microsoft.VisualStudio.VSHelp80.Help2) 
    this.GetService(typeof(Microsoft.VisualStudio.VSHelp.SVsHelp));
        // Display a topic using the F1 keyword.
        // This call opens the Microsoft Document
        // Explorer and displays the specified topic.
        help2.DisplayTopicFromF1Keyword("Owner");
    }
    

    The code obtains the Help2 object from the SVsHelp service.

  8. On the Build menu, click Rebuild Solution to verify the solution builds without errors.

  9. On the Debug menu, click Start Debugging to start the tool window.

    The Visual Studio experimental version starts. If this is the first time you started the experimental version of Visual Studio, you are asked to pick the Environment settings. Choose General Development Settings and click Start Visual Studio.

  10. On the View menu, point to Other Windows and then My Tool Window to start the tool window you created in the MyHelpToolWin project.

  11. Click the button with the text Click Me!

  12. The Microsoft Document Explorer starts and displays a topic titled "Owner Attribute".

    You can choose another F1 keyword in the code help2.DisplayTopicFromF1Keyword("Owner"); to display a topic of your choice.

  13. Close the Help topic and the tool window.

  14. Exit the Visual Studio experimental version.

See Also

Tasks

How to: Create VSPackages (C# and Visual Basic)

Reference

Help2

SVsHelp

Other Resources

Getting Started with Help Content and Integration

Programmatically Interacting with Document Explorer

Microsoft Document Explorer Overview