Home > Basic Functions > Context-sensitive Help > Windows Applications > Windows F1 Field Help
Windows F1 Field Help
You can add context sensitive help to any field within your Windows application so that when a user presses the F1 key while a field has the focus, a help topic specific to that field is displayed. Follow the steps below to add F1 context sensitivity to fields within your Visual Studio 2003/2005 Windows application.
1. Open your Visual Studio Windows application.

2. Double click a field (such as a textbox) to open the code window.
3. Select 'KeyDown' from the 'Events' list

4. Add the following code to the "Sub Textbox1_Keydown" event:
Open a Dynamic Help Page
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = 112 Then Help.ShowHelp(Me, "http://www.helpconsole.com/HelpConsole 2007 Help/username.aspx") End If End Sub
Open a Dynamic Help Page (within help system)
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = 112 Then Help.ShowHelp(Me, "http://www.helpconsole.com/HelpConsole 2007 Help/default.aspx?page=username.aspx") End If End Sub
Open a Static Help Page
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = 112 Then Help.ShowHelp(Me, "help\username.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 TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = 112 Then Help.ShowHelp(Me, "help\username.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. Click a textbox and then press F1 to open the help topic for that field.

See also
|