Home > Basic Functions > Context-sensitive Help > Windows Applications > Windows F1 Form Help

Windows F1 Form Help

You can add context sensitive help to any form within your Windows application so that when a user presses the F1 key, a help topic specific to that form is displayed. Follow the steps below to add F1 context sensitivity to a form within your Visual Studio 2003/2005 Windows application.

1. Open your Visual Studio Windows application.


2. Set the 'KeyPreview' property for the form to 'True'

3. Double click the form to open the code window.



4. Select 'KeyDown' from the 'Events' list

5. Add the following code to the "Sub Form2_Keydown" event:

Open a Dynamic Help Page (page only, no contents)
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = 112 Then
        Help.ShowHelp(Me, http://www.domain.com/help/page.aspx?pageid=project_login)
    End If
End Sub


Open a Dynamic Help Page (within help system)
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = 112 Then
        Help.ShowHelp(Me, http://www.domain.com/help/default.aspx?pageid=project_login)
    End If
End Sub


Open a Static Help Page
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = 112 Then
        Help.ShowHelp(Me, "help\project login.htm")
    End If
End Sub

* the url above assumes that the help system is in a sub folder named 'help'


Open a Static Help Page (within help system)
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If e.KeyCode = 112 Then
        Help.ShowHelp(Me, "help\project login.htm")
    End If
End Sub
* Note: a page parameter cannot be passed when a static help system is opened from Visual Studio,  so in order to display a specific page within the help system, the static help system must be created without frames. See Publishing a Static Help System for more information.


ShowHelp Syntax:    Help.ShowHelp(Parent, URL)
Parent - Reference to the current form
URL - The url of the help system



6. Press F5 to run the application. Press F1 to open the help topic for this form.





See also
URL Parameters
Windows Application Help Button
Windows Form Help Button
Windows Field Help Button
Windows F1 Application Help
Windows F1 Field Help