problem with keypress or keydown event

sarmad

Active member
Joined
Jan 22, 2006
Messages
37
Programming Experience
1-3
hi all

i want to use the keydown event and when user press esc key the form

hide and another form show

i use this code


if e.keycode=keys.esc then
"my command"
end if

for the keypress event

msgbox "e.keychar"


but in my forms it did not work and sound like beep come form my speaker( i have many form)


i was test it in the new project and it work fine (have 1 form)

but in my project dont

any idea ?

thanks
 
if you use the KeyDown event:
VB.NET:
If e.Keycode = Keys.Escape Then
'...
End If

if you use the KeyPress event:
VB.NET:
If Asc(e.Kaychar) = Keys.Escape Then
'...
End If


also note with the KeyPress event, KeyPreview on the form HAS to be set to True

with that said, seeing a code snippet is the only way we can help you further
 
ok


Private Sub bb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bb.Click

If My.Forms.colect.rich.Find(TextBox1.Text, (My.Forms.colect.rich.SelectionLength + My.Forms.colect.rich.SelectionStart), RichTextBoxFinds.None) = -1 Then
MsgBox("پایان جستجو")
bb.Text =
"جستجو"
TextBox1.Text = ""
Else
bb.Text = "بعدی"
End If
My.Forms.colect.rich.Find(TextBox1.Text, (My.Forms.colect.rich.SelectionLength + My.Forms.colect.rich.SelectionStart), RichTextBoxFinds.None)
My.Forms.colect.rich.Focus()

End Sub
Private Sub HoverGradientButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HoverGradientButton1.Click
Me.Close()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text <> "" Then
bb.Enabled = True
Else
bb.Enabled = False
End If
End Sub
Private Sub find_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
MsgBox(e.KeyChar)
End Sub

Private Sub find_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If TextBox1.Text = "" Then
bb.Enabled = False
End If
End Sub




its without keypress or keyevent source
 
Back
Top