Tab and Enter keys

sirmilt
08-08-2007, 10:25 AM
I'm working on an application with a number of MaskTextBoxes to enter time values. There are two sets of In and Out boxes for every day of the week for two weeks a total of 56 boxes.

I want the user to enter a time and then press either the Tab key or the Enter key to convert from text to a date, validify the time and move to the next control.

Unfortunately, the tab key moves the focus to the next control but does not call the KeyDown or KeyUp function. The Enter key runs the code but does not move the focus to the next control.

I want to give the user the option of pressing either Tab or Enter and can't figure out how.

Has anyone any suggestions?

torpkevuk
08-08-2007, 11:31 AM
well an easy (although clunky) approach of moving focus to the next control would be:


Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
TextBox2.Focus()
End If
End Sub

AtmaWeapon
08-08-2007, 12:12 PM
Is there any particular reason why you are using MaskedTextBox instead of DateTimePicker for date/time entry? The advantages are as follows: It is impossible to pick an invalid date or time. The user can use a calendar to pick the date value. You don't have to parse anything or write your own error handling. If you need to ensure dates/times are in certain ranges, the Validating event provides this functionality.I'd suggest giving that control a shot (using a custom format for entry) before spending too much time trying to reinvent the wheel.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum