Making Help Authoring a Pleasure to Do
Free DownloadStart your free trial now

Article

How to Connect HTML Help with your .NET Application

If you are a .NET (C#, VB.NET, etc.) developer, you can easily integrate an HTML Help (CHM) system with your application. The .NET library has built-in support for CHM files which is provided by the classes "HelpProvider" and "Help".

Providing Help for Controls

  1. Add a HelpProvider component to the form. This will add the following properties to other controls: HelpKeyword, HelpNavigator, HelpString, ShowHelp.
  2. Set the full path to your CHM file to the HelpProvider.HelpNamespace property. If the CHM file is located in the same directory with your application's executable file, you can set only the filename.
  3. To enable the help [?] button on the form's caption area, set values of the following form properties: HelpButton = True, MaximizeBox = False, MinimizeBox = False.
  4. Now you can use the mentioned control properties to provide Help for a control when the user focuses it and presses F1 or selects the [?] button and clicks on it. For example, the control can display the topic with Context Id 20. To achieve that, set its HelpKeyword propery to 20 and its HelpNavigator property to TopicId.

The HelpKeyword value depends on the value of the HelpNavigator property that specifies which elements of the help system should be displayed. You can refer to the Visual Studio help system for more information on the members of the HelpNavigator enumeration.

Using the ShowHelp() Method of the Help Class

You can also use the ShowHelp method provided by the Help class from the code of your application.

Displaying a help topic by its Context Id

Help.ShowHelp(this, "c:\my_help_file.chm", HelpNavigator.TopicId, "30");

where "c:\my_help_file.chm" is the full path to your CHM file and "30" is the Context Id of the topic to display, as specified in your help project.

Displaying the Table of Contents

Help.ShowHelp(this, "c:\my_help_file.chm", HelpNavigator.TableOfContents, "");

Displaying the Index

Help.ShowHelp(this, "c:\my_help_file.chm", HelpNavigator.Index, "");

A Utility HTMLHelpClass

On our website, you can download a simple module implementing a utility HTMLHelpClass for C# and VB.NET. By adding this module to your project, you can set the HelpNamespace property of HTMLHelpClass only once (for example, in the Form1() event for C# and in the Form1_Load event for VB.NET) and then use it for HTML Help calls. This class also provides a GetLocalHelpFileName() method that can be used to get the full path to the CHM file located in the same directory as your application's .EXE file.

For example (C#):

public partial class Form1 : Form {
  public Form1() {
    InitializeComponent();
    HTMLHelpClass.HelpNamespace = HTMLHelpClass.GetLocalHelpFileName("MyHelpFile.chm");
    helpProvider1.HelpNamespace = HTMLHelpClass.GetLocalHelpFileName("MyHelpFile.chm");
  }
}

private void button1_Click(object sender, EventArgs e) {
  Help.ShowHelp(this, HTMLHelpClass.HelpNamespace, HelpNavigator.TableOfContents, "");
}

For example (VB.NET):

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  HTMLHelpClass.HelpNamespace = HTMLHelpClass.GetLocalHelpFileName("MyHelpFile.chm")
  HelpProvider1.HelpNamespace = HTMLHelpClass.GetLocalHelpFileName("MyHelpFile.chm")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Help.ShowHelp(Me, HTMLHelpClass.HelpNamespace, HelpNavigator.TableOfContents, "")
End Sub

Download HelpSmith

You can download HelpSmith and start creating help files and documentation in multiple formats. For new users, HelpSmith includes sample help projects that will help you get started with the product quickly.

Detail Value
Product HelpSmith 7.1 (Build 17.920)
Filename HelpSmithSetup.exe
File size 40 MB
Platform Windows 10/8/7/Vista/XP