I need to use Function keys within a form I've created. The problem I'm having is determing the correct routine to fire it off. Here's what I'm attempting to do:
In Form1 (actually called "OrderEntry2"), I want to give the user the option of keying in a part number into the "txbPartNo" textbox. Or, if they don't know the part number, I want to allow them to hit 'F5' to bring up Form2 (called "Popup_PartNo) to find that part number based on the beginning characters that they will enter on that form.
Likewise, should the user not know the beginning characters of the part number, I'd want to give them the option of finding the part number based on a word within the part description. Again I want to allow them to hit 'F5' to bring up Form2 (called "Popup_PartNo) to perform the routine.
My first inclination was to allow the user to give FOCUS to either "txbPartNo" textbox or "txbDescription" textbox to choose which way they want to search. So I wrote the following:
Public Sub txbPartNo_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbPartNo.GotFocus If e.KeyValue = Keys.F5 Then FuncKeysModule(e.KeyValue) e.Handled = True End If End Sub Public Sub txbDesc_GotFocus(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txbDesc.GotFocus If e.KeyValue = Keys.F5 Then FuncKeysModule(e.KeyValue) e.Handled = True End If End Sub Public Sub FuncKeysModule(ByVal value As Keys) 'Check what function key is in a pressed state, and then perform the corresponding action. Select Case value Case Keys.F5 Dim searchtype As Integer If txbPartNo.Focused = True Then Popup_PartNumbers.Label1.Text = "Enter the beginning characters of the Part Number to search" searchtype = 1 txbSearchType.Text = searchtype End If If txbDesc.Focused = True Then Popup_PartNumbers.Label1.Text = "Enter a word from the Part Number Description to search" searchtype = 2 txbSearchType.Text = searchtype End If Popup_PartNumbers.ShowDialog() End Select End Sub
As it stands right now, 'F5' doesn't bring up the Popup_PartNumbers form.
So, several questions:
1) Can I use this one function key ('F5') for both routines (albeit I'm trying to choose one or the other)?
2) Am I using the correct event (GotFocus) to fire this of?
3) Is the code "If txbDesc.Focused = True Then" being correctly used (see above)?
4) If I'm using the wrong events, can you suggest what would be better to use?
In advance, thanks for your help.