I have a form and input txtbox. When I press enter I want to display a msgbox. But if the user press enter. The program gets stuck in repeating the msgbox. How do I stop this?
Printable View
I have a form and input txtbox. When I press enter I want to display a msgbox. But if the user press enter. The program gets stuck in repeating the msgbox. How do I stop this?
show us your code otherwise we cannot help you
Set your Form's KeyPreview property to True and in your KeyPress event of the Form, have the following code:
VB Code:
If KeyAscii = 13 Then msgbox "Your text goes here" End If
Show us your code so that we can help you find where and why you get stuck in the loop.
Hi,Quote:
Originally Posted by mnavas
You can try this;
VB Code:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then MsgBox("Your text goes here") End If End Sub
Wkr,
sparrow1
I tested this a bunch of times without getting stuck in any loops.
VB Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.Enter Then MessageBox.Show("Hello There") End If End Sub
VB Code:
Select Case e.KeyCode Case Keys.Enter If DataSetp.Tables("workers").Rows.Count = 1 Then ' Else MsgBox("Error", MsgBoxStyle.Critical, "Error") End If Mtxlogin.Text = String.Empty End Select
I found the error I use keyup event....instead of kepress... now is working fine.. thank to all.