1. Home
  2. Computing & Technology
  3. Visual Basic
Managing Windows Forms
The ShowHelp Method of the Help Object

Although the HelpButton will work for a lot of things, there are several other techniques to choose from. One is the ShowHelp method of System.Windows.Forms.Help. This technique will call a URL (a web page that can either be local or on a network). Although this is a method that can be used in a lot of different ways, to get the idea across, here's a code example where the text display for the Lucky Seven program is just replaced by the ShowHelp method and the web page that is displayed is the main page at the About Visual Basic web site as an example.

Private Sub textBox_HelpRequested( _
    ByVal sender As Object, _
    ByVal hlpevent _
      As System.Windows.Forms.HelpEventArgs) _
    Handles MyBase.HelpRequested
    ' This event is raised 
    ' when the F1 key is pressed or the
    ' Help cursor is clicked 
    ' on any of the component fields.
    Dim Parent As System.Windows.Forms.Control
    Parent = sender
    Windows.Forms.Help.ShowHelp( _
      Parent, "http://visualbasic.about.com")
End Sub

The last statement could also reference a local URL like this:

Windows.Forms.Help.ShowHelp( _
        Parent, "c:\vbnet03sbs\chap14\readme.txt")

In this case, the readme.txt file will be displayed by whatever program is registered to process txt files on the local computer - probably NotePad. The readme.txt file could also be converted to a web page and displayed in a web browser.

And don't forget that VB.NET structured error handling also has the ability to display Help. Here's a code snippet showing how to use that for an Overflow error.

Dim Msg As String
Err.Clear
' Suppress errors for demonstration purposes
On Error Resume Next   
Err.Raise(6)   ' Generate "Overflow" error.
Msg = "Press F1 or HELP to see " & Err.HelpFile & _
" topic for this error"
MsgBox (Msg, , "Error: ")
Next page >>>   The HelpProvider Component
Page 1, 2, 3, 4, 5
Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.