הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, March 2, 2016 1:05 AM
Hai
I Have four TextBoxes . If Textbox1 is empty or null and if I press Entre, the focus of the textbox cant move and I want to blink the cusrsor on the same textbox. How ?
I use the following code,
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.Text = "" And (e.KeyChar = Convert.ToChar(Keys.Enter)) Then
Me.TextBox1.Focus()
TextBox1.SelectAll()
End If
end sub
All replies (4)
Monday, March 7, 2016 3:09 PM ✅Answered
Try this to blink it yellow
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If TextBox1.Text = "" And (e.KeyChar = Convert.ToChar(Keys.Enter)) Then
'Me.TextBox1.Focus()
'TextBox1.SelectAll()
Debug.Print("Enter on empty txb1")
Dim textboxOriginalBackgroundColor As New Color
textboxOriginalBackgroundColor = TextBox1.BackColor
'Change it to Yellow to wanr of empty box
TextBox1.BackColor = Color.Yellow
'Wait for 1 second 'remember Imports System.Threading
TextBox1.Refresh()
Thread.Sleep(500)
'Change back
TextBox1.BackColor = textboxOriginalBackgroundColor
Else
'Process normal
End If
End Sub
Wednesday, March 2, 2016 2:15 AM
Hi,
I'm afraid you've made a typing error. It would be "TextBox2", instead of "TextBox1".
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress
If TextBox1.Text = "" And (e.KeyChar = Convert.ToChar(Keys.Enter)) Then
Me.TextBox2.Focus()
Me.TextBox2.SelectAll()
End If
end sub
Regards.
Monday, March 7, 2016 2:54 PM
No Sir, If Textbox1 is null or empty then focus should be in the same textbox, ie textbox1.
Monday, March 7, 2016 3:05 PM
stopping cursor in Textbox1 until and unless user enters some value.