Saturday, October 10, 2009

Using the HelpProvider to show an HTML help page

In .NET WinForms a HelpProvider component is available to let you add help functionality to your application. While I tried to use this component in one of my applications, I noticed it is poorly documented. I hope this post can help you get started.

The HelpProvider

HelpProvider is an Expander Provider class that contains a number of hashtables to externally add help related properties to windows forms controls. The HelpNamespace string property identifies a help system and must be set to use HelpKeyword/HelpNavigator. It is NOT a namespace. It can be a uri or local file name or possibly other things as well.

The four directly manipulated hashtable properties are:

  • ShowHelp – a Boolean flag that enables the display of help through the HelpProvider.
  • HelpString – a string to display in a pop-up window. Typically activated by clicking on the control when the cursor is a “?” or when the control has focus and HelpNamespace is null.
  • HelpKeyword – a string to identify the help request passed to a help system. Optional. Used to steer a help system to the correct point.
  • HelpNavigator – an enumeration value that guides the help system in what to do with the HelpKeyword.

The HelpProvider registers event handlers on the control’s HelpRequested and QueryAccessibilityHelp events if enabled and minimally configured.

The Help class provides the actual methods for displaying help.

   1:  Help.ShowPopup(parent, caption, location)
   3:  Help.ShowHelp(parent, helpNamespace[, helpNavigator[, helpKeyword]])

If HelpNamespace uses “http:” or “https:” schemes then only HelpNavigator.Topic can be used which appends “#”+HelpKeyword onto HelpNamespace.

No comments: