[vb.net] Keyboard control focus move

Source: Internet
Author: User
Tags bool
Control---Keyboard control focus Move---
In a database project, there must be a form for the input data. Most of the input staff headache is after each fill out a data, to operate the mouse, or another hand click tab (but still very troublesome). The most humane thing is: press ENTER (in the keypad input as long as one hand is OK), You can also use the arrow keys to control.

The first step: the KeyPreview property of form is true
Step two: Set the TabIndex in order as needed
Step three: Write a method with the following code:

'---focusmove is Function name--
'---controlname is the control ' 's Name Which you want to-use---
Private Sub Focusmove () Sub Focusmove (ByVal sender as Object, ByVal e as System.Windows.Forms.KeyPressEventArgs) Handles Co Ntrolname1.keypress, controlname2.keypress
If E.keychar = ChrW (Then)
'---selectnextcontrol is a Function would be introduced next---
Selectnextcontrol (sender, True, true, true, False)
End If
End Sub

Selectnextcontrol's instructions are from MSDN:

Activates the next control.

[Visual Basic]
Public Function Selectnextcontrol (_
ByVal ctl as Control, _
ByVal forward as Boolean, _
ByVal Tabstoponly as Boolean, _
ByVal Nested as Boolean, _
ByVal Wrap as Boolean _
) as Boolean

[C #]
public bool Selectnextcontrol (
Control CTL,
BOOL Forward,
BOOL Tabstoponly,
BOOL nested,
BOOL Wrap
);

[C + +]
Public:bool Selectnextcontrol (
Control* ctl,
BOOL Forward,
BOOL Tabstoponly,
BOOL nested,
BOOL Wrap
);

[JScript]
Public Function Selectnextcontrol (
Ctl:control,
Forward:boolean,
Tabstoponly:boolean,
Nested:boolean,
Wrap:boolean
): Boolean;

Parameters
Ctl
The control from which to start the search.
Forward
True to move forward in the tab order, or False to move back in the tab order.
Tabstoponly
True indicates that the control with the TabStop property set to False is ignored, and false indicates that it is not ignored.
Nested
True indicates that the nested child controls (children of child controls) are included, and False indicates that they are not included.
Wrap
True indicates that the first control begins the search in the Tab order after the last control is reached, and False indicates that the search is not continued.
return value
True if the control is active, or false.

Note
If you set the control's controlstyles.selectable style bit to true, the control is contained in another control and all its parent controls are visible and enabled, the Selectnextcontrol method activates the next control in the Tab order.

Windows forms controls in the following list are not selectable. Controls derived from controls in this list are also not selectable.

Label
Panel
GroupBox
PictureBox
ProgressBar
Splitter
LinkLabel (when there is no link in the control)
Requirements
Platforms: Windows, Windows NT 4.0, Windows ME, Windows XP, Windows xp-based Home Edition, Windows XP Professional, Windows Server 2003 series


The final note is the TabIndex settings, if the control in the GroupBox, then GroupBox in the TabIndex order, that is, if TextBox1 in GroupBox1, then Groupbox1.index=1, Textbox1.index=2. And in the selectnextcontrold of the parameters of the nested=true, you can. There are some details you should pay more attention to when you use them in peacetime.
---end---




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.