1. Home
  2. Computing & Technology
  3. Visual Basic
Managing Windows Forms
Going Beyond the Book: Providing Help

The first example in the chapter is a very simplified Help window. Although the purpose of this example is really just to demonstrate how to manage multiple forms in a project, you might be left with the impression that this is the recommended way to provide help screens for your system.

NOTHING could be further from the truth!

One of the bigger upgrades in VB.NET is the addition of new ways to provide help in a system. Most of them are based on extensions to VB.NET forms. Studying the ways help can be provided in VB.NET illustrateS both how an important VB.Net Namespace - Forms - is extended, and also shows you some valuable programming tips for help that you can use in your code.

Help can be very sophisticated and complex or very simple. Here's an overview.


 Topics
  From The Lesson
VB.NET structured error handling
 
RoboHelp
 
Microsoft MSDN
HTML Help Workshop

 
Microsoft MSDN
HTML Help SDK

 
User Interfaces in VB .NET
a book by Matthew MacDonald

 

As our first example, let's change the help system for the Lucky Seven example from the book and use the HelpButton property and the HelpRequested event for the Lucky Seven form. This property is already there in the form. All we are going to do is put it to use. HelpButton allows you to either press the F1 key or click the HelpButton to get help. To add this to the Lucky Seven project in the book, follow these steps.

  1. Load the "Multiple Forms" project from the library of projects provided with the book from the folder for Chapter 15.
  2. Delete the Help Button from the Lucky Seven form and the event subroutine that handles it (Button3_Click).
  3. Open the Properties window for the Lucky Seven form (named Form1) and change ...

    HelpButton     True
    MaximizeBox    False
    MinimizeBox     False

    The HelpButton property has no effect unless the MaximizeBox and the MinimizeBox are disabled.

Now it's time to add the programming that will display the same ReadMe.txt file using the HelpButton object. This object will raise an event called HelpRequested for specific components, or using the HelpButton. To do this ...

  1. Add the following code to the Form1 class. Since this is just a modification of the code that is provided in the book, it's easier (and more error proof) to copy and paste it, then change the parts of the code that are different.
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 StreamToDisplay As StreamReader
    Dim frmDialog As New HelpInfo
    frmDialog.ShowDialog()
    StreamToDisplay = _
      New StreamReader( _
      "c:\vbnet03sbs\chap14\readme.txt")
    frmDialog.Text = StreamToDisplay.ReadToEnd
    StreamToDisplay.Close()
    hlpevent.Handled = True
End Sub 'textBox_HelpRequested
  1. Finally, remember to add this statement at the top of the program ...


  2. Imports System.IO 'for StreamReader class
HelpButton

To use the HelpButton, click the button (it's the one with the question mark in it at the top right) then click inside any of the components. If you click on a blank spot in the form, nothing will happen. This is because the HelpButton is designed to allow you to display different things for different components but in this simplified example, we just selected all of the components - but not the form - using the Handles MyBase.HelpRequested clause in the Sub textBox_HelpRequested declaration. The cursor then changes into the HelpRequsted cursor and when you click again, the Sub textBox_HelpRequested code is executed to display the file. The HelpRequested event code is also executed if you press F1.

Next page >>>   The ShowHelp Method of the Help Object
Page 1, 2, 3, 4, 5
Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

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

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

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

All rights reserved.