Preventing Lost Focus in TextBox Control

  • Thread starter Thread starter Joe Keller
  • Start date Start date
J

Joe Keller

Hello,

How would I go about preventing the focus from leaving a text box control?
I am building a custom text box for which the data has to be properly
entered before I would let the user move focus to another control. The
"Validating" event does not appear to be supported in the CF.

Thanks,

Joe
 
Hi,
both 'validating' and 'validated' are supported by the .Net CF - what
appears to be the problem?

Pete
 
I set "e.Cancel = true" on the validating event and yet the focus still
shifts to the other control. Am I mis-interpreting how the Validating event
is supposed to work? I don't want my textbox control to lose focus unless
the data in the control passes validation.

joe
 
Ahh...never mind...I found it - I wasn't calling the "Focus()" method after
the validation failed to re-focus on the textbox control :)

Joe
 
This behaviour is different compared to .net framework,
ie, you need to set focus yourself on CF.

Is this by design, or a bug?

To re-create the bug/feature, create a form, drop 2 TextBoxes
on it, an paste the code below. Type an "a" (in TextBox1) and
press Enter twice.
On .net framework, the TextBox2 will get focus.
On .net CF, no control will get focus.
--------------------------
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text = "a" Then
MsgBox("varning")
End If
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = vbCr Then
TextBox2.Focus()
End If
End Sub
--------------------------
 
Back
Top