471,604 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,604 software developers and data experts.

VB.Net Key Press

Hi,
How can we use the down and up keys in vb.net using Keypress?Any one can help me? Pls.
Jun 9 '07 #1
5 34087
kenobewan
4,871 Expert 4TB
Welcome to TSDN. I suggest using KeyCode values in the KeyUp (or KeyDown) event, i.e. keypress won't work. HTH.
Jun 9 '07 #2
Hi,
How can we use the down and up keys in vb.net using Keypress?Any one can help me? Pls.

The KeyPress event is not missing. If you want to get the ASCII code of the key pressed in the KeyPress event, use the KeyPressEventArgs' KeyChar property to get the Char representing the key pressed, and then convert it to an ASCII keycode using AscW. Also, if you want to determine whether a Char is numeric or alphabetic, you can use the IsNumber and IsLetter shared methods of Char. For example:
Code:

Private Sub frmGame_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles MyBase.KeyPress
Dim keyascii As Integer = AscW(e.KeyChar)
Dim bNumber As Boolean = Char.IsNumber(e.KeyChar)
Dim bLetter As Boolean = Char.IsLetter(e.KeyChar)
End Sub
Jun 9 '07 #3
Welcome to TSDN. I suggest using KeyCode values in the KeyUp (or KeyDown) event, i.e. keypress won't work. HTH.

Thank You For your Suggestion.It is very useful to me.
Jun 11 '07 #4
but how to organize another scenario?

1. you have a loop in
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

2. pressing a key you have to jump in
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

3. and go back to
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dec 29 '07 #5
CyberSoftHari
487 Expert 256MB
Call the Form1_KeyPress in Form1_Paint.
Note: better generate a method and call anywhere. Event should call only on event activated.
Dec 29 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Brian Basquille | last post: by
3 posts views Thread by John Howard | last post: by
6 posts views Thread by Johan Svedberg | last post: by
5 posts views Thread by junk mail | last post: by
1 post views Thread by =?Utf-8?B?QXNhZg==?= | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.