Article View: comp.os.ms-windows.programmer.misc
Article #1622Re: Enter key in VB
From: Galen Raben
Date: Wed, 14 Oct 1992 23:01
Date: Wed, 14 Oct 1992 23:01
44 lines
2771 bytes
2771 bytes
Jon, In comp.os.ms-windows.programmer.misc you write:
{stuff deleted...}
>If I create a form in a window, is it possible to prevent the ENTER key from
>selecting the default control. I realise I can prevent a control from being
>the default but what I really need is a collection of text boxes for input
>with the enter key changing focus between each one. Outside this control
>area, I need two control buttons which are selected using the mouse. For
>example, if the user presses enter in the last text box, I don't want the OK
>or CANCEL control buttons to be triggered. This is really simple, probably,
>but I need to know before I purchase software.
Yes, this is really simple! You can intercept keystrokes in the KeyPressed
event procedure, writing some simple code in the event will allow you to
process the Enter key such that it will change focus from one text box to
the next...
The code looks something like this:
If KeyAscii = 13 Then ' check for Enter keypress
KeyAscii = 0 ' this fixes an annoying beep when using Enter to change focus
Text2.SetFocus ' set the focus to your next textbox
End If
You can also change the tab order of the textboxes (though you are essentially
doing it directly in the event with the SetFocus method)... If you modify the
tab order you could prevent someone from tabbing to the OK or CANCEL buttons,
the only way they could get there is by the mouse only. I usually keep my
OK and CANCEL buttons in the tab order just in case I have the one in a
million customers that refuse to use a mouse! You have lots of control over
what happens during key presses, mouse clicks, mouse movements!
I've used VB (for Windows) for over a year now and am very pleased!! My only
complaints have been the current limitation to 16 color graphics (even if you
have a 256 color or 24bit driver) and lack of documentation on hooking to
Windows Help (which MS has since released in the VB Pro Toolkit).
One of the neatest things about it is that if you can't do something directly
with a VB statement (such as creating a "transparent" control), you can always
tell VB to hook the Windows API functions and create what you need yourself!!
Hope this Helps!!
- Galen -
galenr@hpgrla.gr.hp.com
Technical Details
Message-ID:
<36560011@hpgrla.gr.hp.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!caen!sdd.hp.com!scd.hp.com!hplextra!hpfcso!hpgrla!galenrReferences:
<1992Oct12.105905@axion.bt.co.uk>Show Full Headers
Complete Article Headers
From: galenr@hpgrla.gr.hp.com (Galen Raben) Date: Wed, 14 Oct 1992 23:01:40 GMT Subject: Re: Enter key in VB Message-ID: <36560011@hpgrla.gr.hp.com> Organization: Hewlett-Packard, Greeley, CO Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!eff!sol.ctr.columbia.edu!caen!sdd.hp.com!scd.hp.com!hplextra!hpfcso!hpgrla!galenr Newsgroups: comp.os.ms-windows.programmer.misc References: <1992Oct12.105905@axion.bt.co.uk> Lines: 45