Methods of implementing What's This Help (Article)
Author: PB
Version Compatibility: Visual Basic 6
Instructions: Copy the declarations and code below and paste directly into your VB project.
This article provides a number of ways to implement how to show the tool tip help for any control within the form. The below methods are applicable to VB 5.0/VB 6.0 programs.
There are 4 access techniques for providing What's This Help in an application. The WhatsThisHelp property must be set to True for any of these techniques to work.
Note: Here its assumed that one knows how to work with HLP file and how to map the topic within a help file into the numeric values.
METHOD 1:
Providing a What's This button in the title bar of the form using the WhatsThisButton property. The mouse pointer changes into the What's This state (arrow with question mark). The topic displayed is identified by the WhatsThisHelpID property of the control clicked by the user.
Type the following code in Form_load event:
Private Sub Form_Load() 'Method 1 ********** 'Displaying help 'Assign the application help file with one available HLP 'filename. App.HelpFile = App.Path & "\userguide.hlp" 'Make sure that the following properties are set accordingly. ' Form properties ' MaxButton = False ' MinButton = False ' WhatsThisButton = True ' WhatsThisHelp = True ' With this, you will find a What's this Help sign on form ' Title along with ' close button. 'Here we assume that all the related topics within HLP file 'are mapped to some numeric values. This nummeric value will be 'used to assign the context sensitive help for the control. Text1.WhatsThisHelpID = 1011 End sub
when you click on whats this help in title bar of form, the mouse pointer changes to What's this help icon. Move over to a control and click on it, it will show you the help for that control.
**************************
METHOD 2:
Invoking the WhatsThisMode method of a form. This produces the same behavior as clicking the What's This button without using a button. For example, you can invoke this method from a command on a menu in the menu bar of your application.
Copy the following code:
Private Sub Form_Load() 'Method 2 ********** 'Displaying help 'Assign the application help file with one available HLP 'filename. App.HelpFile = App.Path & "\userguide.hlp" 'Method 2 includes help without showing the whats this help 'in form's title. 'Make sure you have made following changes in: 'Form properties ' MaxButton = True ' MinButton = True ' WhatsThisButton = False ' WhatsThisHelp = True ' With this, one will see 3 buttons on the form title bar, ' ie,minimize maximize and close. No help button is displayed. Text1.WhatsThisHelpID = 1011 End sub
Put a cmdHelp (Command button) on the form. Name the command button as cmdHelp. Write following in its command_click event.
Private Sub cmdHelp_Click() 'FrmMeth1 is name of the form. frmMeth1.WhatsThisMode 'when you click on cmdHelp, you will see the 'mouse pointer change to what's this help icon. 'move that over a control (textbox etc) and click, you 'will find the help tooltip for that control End Sub
***************************
METHOD 3:
Invoking the ShowWhatsThis method for a particular control. The topic displayed is identified by the WhatsThisHelpID property of the control.
Copy the following code:
Private Sub Form_Load() 'Method 3 ********** 'Displaying help 'Assign the application help file with one available HLP 'filename. App.HelpFile = App.Path & "\userguide.hlp" 'Method 3 includes help without showing the whats this help 'in form's title bar. This show the tool tip help by using 'show help method of the control itself. 'Make sure you have made following changes in: 'Form properties ' MaxButton = True ' MinButton = True ' WhatsThisButton = False ' WhatsThisHelp = True ' With this, what's this help icon does not appear in the ' form's ' title bar. Text1.WhatsThisHelpID = 1011 End sub
Put the following in Textbox_click event:
Private Sub Text1_Click() Text1.ShowWhatsThis End Sub
When the above textbox control is clicked, the tooltip help appears for the control.
***************************
METHOD 4:
This display 'what's this ?' on the right click of any of the controls used in the form. This is the most commonly used method in various applications to show the tool tip help.
The following things must be done:
- Create Menu in the form:
Menu Caption: Help
Menu name: mnuHelp - Create a submenu within HELP menu as
Menu Caption: What's This ?
Menu name: mnuWhatsThis - Make the Help as non-visible by,
mnuHelp.visible = false
- Add a command button on the form:
Name: cmdHelp
Caption: Help - Copy following in global variable declaration
Dim myControl As Control
- Copy following in the form_load event:
Private Sub Form_Load() ' Method 4 ********* 'Display help ' Assign the application help file with one available HLP ' filename. App.HelpFile = App.Path & "\userguide.hlp" ' This method will show the tool tip help on right click of a ' control. 'Make sure you have made following changes in: 'Form properties ' MaxButton = True ' MinButton = True ' WhatsThisButton = False ' WhatsThisHelp = True ' With this, what's this help icon does not appear in the ' form's ' title bar. cmdHelp.WhatsThisHelpID = 1011 mnuHelp.Visible = False End Sub
- Copy following in the control's Mouse up event:
Private Sub cmdHelp_MouseUp(Button As Integer, _ Shift As Integer, X As Single, Y As Single) 'Check for the right-click of mouse If Button = vbRightButton Then Set myControl = cmdHelp PopupMenu mnuHelp End If Set myControl = Nothing End Sub
- Once the above process is over, run the project. When the right click is done for Help button. It will show the menu as 'What's This ?'. Clicking on it will show the help of that control.