Using UP ARROW and DOWN ARROW Keys to Move the FocusLast reviewed: June 21, 1995Article ID: Q100413 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0 - Standard and Professional Edition of Microsoft Visual Basic for MS-DOS, version 1.0
SUMMARYYou can trap for the UP ARROW and DOWN ARROW extended keyboard keys in some Visual Basic controls by placing code in the KeyDown event procedure. The code uses KeyCode values to trap the UP ARROW and DOWN ARROW keys. You cannot, however, trap the keys in all Visual Basic controls because some controls already have built-in functionality for the UP ARROW and DOWN ARROW keys, so there is no KeyDown event generated.
MORE INFORMATIONThe information in this article is provided to show that it is possible to trap the UP ARROW and DOWN ARROW keys, however Microsoft does not recommend that you implement it because the UP ARROW and DOWN ARROW keys have standard, predefined behavior on some controls. Microsoft recommends that you use the standard method for using the keyboard to move the focus; that is, use the TAB and SHIFT+TAB keys or use the access keys.
Step-by-Step Example for Moving the Focus Using UP ARROW and DOWN ARROW1. Start Visual Basic or from the File menu, choose New Project(ALT, F, N) if Visual Basic is already running.
Sub Picture1_KeyDown(KeyCode AS INTEGER, Shift AS INTEGER) IF KeyCode = 38 Then '* 38 = up arrow key Text2.SetFocus Text2.SelStart = 0 '* set the cursor to the start END IF IF KeyCode = 40 Then '* 40 = down arrow key Text1.SetFocus Text1.SelStart = 0 '* set the cursor to the start END IF END SUB
Sub Text1_KeyDown(KeyCode AS INTEGER, Shift AS INTEGER) If KeyCode = 38 Then '* 38 = UP ARROW key Picture1.SetFocus End If If KeyCode = 40 Then '* 40 = DOWN ARROW key Text2.SetFocus Text2.SelStart = 0 '* set the cursor to the start End If End Sub
Sub Text2_KeyDown(KeyCode AS INTEGER, Shift AS INTEGER) If KeyCode = 38 Then '* 38 = UP ARROW key Text1.SetFocus Text1.SelStart = 0 '* set the cursor to the start End If If KeyCode = 40 Then '* 40 = DOWN ARROW key Picture1.SetFocus End If End Sub If you use the LEFT ARROW or RIGHT ARROW keys, you can scroll in a Text box, but these keys are ignored in the Picture box in this example.
|
Additional reference words: 2.00 3.00 B_VBmsdos 1.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |