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
On the File menu, point to New, and then click Project.
The New Project dialog box appears.
In the Project types pane, expand Other Project Types, and then click Extensibility.
In the Templates pane, click Visual Studio Integration Package.
In the Name box, type MyHelpToolWin.
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.
On the Select a Programming Language page, select Visual C#. For the key-file entry, accept the default setting, and click Next.
On the Basic VSPackage Information page, accept the default values and click Next.
On the Select VSPackage Options page, select Tool Window and click Next.
On the Tool Window Options page, accept the default values and click Finish.
The MyHelpToolWin solution is created and appears in the Solution Explorer.
On the Build menu, click Build Solution to verify the solution builds without errors.
To add Help2 functionality to the tool window
In Solution Explorer, click MyHelpToolWin.
On the Project menu, click Add Reference.
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.
In Solution Explorer, click MyControl.cs.
On the View menu, click Designer if the user control is not already in Design view.
Double-click the button control with the text, Click Me!
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"); }
On the Build menu, click Rebuild Solution to verify the solution builds without errors.
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.
On the View menu, point to Other Windows and then My Tool Window to start the tool window you created in the MyHelpToolWin project.
Click the button with the text Click Me!
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.
Close the Help topic and the tool window.
Exit the Visual Studio experimental version.
See Also
Concepts
Getting Started with Help Content and Integration
Programmatically Interacting with Document Explorer
How to: Create VSPackages (C# and VB)
Microsoft Document Explorer Overview