473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to handle keypress in VB.NET

sgrec7
59
Hi, sgrec7 here.

so anyway in VB 6 this is how you would use keyascii's

private sub form_keypress (keyascii as integer)

if keyascii = 13 enter key then
end
end if

end sub

that was easy, but how the f&(# do you do that in VB 8 ???? any help will be much appreciated !! thanks
Aug 31 '07 #1
10 18862
QVeen72
1,445 Expert 1GB
Hi,

IN VB8, it is :

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
  2.         If e.KeyCode = Keys.Enter Then
  3.             MsgBox("Veena")
  4.         End If
  5.     End Sub
  6.  
REgards
Veena
Aug 31 '07 #2
Killer42
8,435 Expert 8TB
A couple of questions.
  • VB6 also had a KeyUp event. Is there an equivalent of KeyPress?
  • What the heck is VB8? Didn't they stop numbering them that way after version 6?
Aug 31 '07 #3
QVeen72
1,445 Expert 1GB
Hi Killer,

Yes, they stopped Numbering, but still

VB.Net2003 is VB7
VB.Net2005 is VB8.

VB7 and VB8 both have same KeyPress Event..

REgards
Veena
Aug 31 '07 #4
Killer42
8,435 Expert 8TB
Yes, they stopped Numbering, but still
VB.Net2003 is VB7
VB.Net2005 is VB8.
Thanks. This is the first time I've heard them referred to that way.

But I thought there was also a 2002 version of VB.Net, though. What was that, VB6.5?
Aug 31 '07 #5
A couple of questions.
  • VB6 also had a KeyUp event. Is there an equivalent of KeyPress?
  • What the heck is VB8? Didn't they stop numbering them that way after version 6?
Hey, VB8 is another name for VB 2005... there is a good page about it on wikipedia... just wiki VB 2005.

In response to ur comment, yes there is a Keypress equivalent....

The following code will capture a keypress and then use the keycodes to determine which key was pressed... in this case check for the enter key...

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 
  2. _ Handles TextBox.KeyPress
  3.         If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
  4. 'DO SOMETHING'
  5.         End If
  6.     End Sub
  7.  
This particular checks for a keypress in a text box, but i think you can check for anykeypress by replacing the textbox with the name of the form or other component.

Hope this helps...

Martin
Aug 31 '07 #6
Killer42
8,435 Expert 8TB
Hey, VB8 is another name for VB 2005... there is a good page about it on wikipedia... just wiki VB 2005.
Ah yes, I see. QVeen72 was mostly right. VB2003 is referred to as VB7.1.
Aug 31 '07 #7
sgrec7
59
A couple of questions.
  • VB6 also had a KeyUp event. Is there an equivalent of KeyPress?
  • What the heck is VB8? Didn't they stop numbering them that way after version 6?
Yea sorry Killer, it's known as both "VB 8" and "Visual Basic 2005"
Aug 31 '07 #8
sgrec7
59
...The following code will capture a keypress and then use the keycodes to determine ...
You know Martin, I think that might actually work !! thanks!!

And i forgot to say before, thanks to the admins for changing the name of my thread more appropriate to the subject. Thanks guys
Aug 31 '07 #9
sgrec7
59
Hey, VB8 is another name for VB 2005... there is a good page about it on wikipedia... just wiki VB 2005.

In response to ur comment, yes there is a Keypress equivalent....

The following code will capture a keypress and then use the keycodes to determine which key was pressed... in this case check for the enter key...

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) 
  2. _ Handles TextBox.KeyPress
  3.         If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
  4. 'DO SOMETHING'
  5.         End If
  6.     End Sub
  7.  
This particular checks for a keypress in a text box, but i think you can check for anykeypress by replacing the textbox with the name of the form or other component.

Hope this helps...[/i]
Martin, that code was sooo correct that I'm going to quote you again !!! there is one problem though...


Expand|Select|Wrap|Line Numbers
  1.  
  2. _ Handles TextBox.KeyPress
  3.  
  4.  
needs to be changed to:


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles me.keypress
  3.  
  4.  
so that it reads it correctly.

also say i wanted something to happen on key "2" keyascii value of 50 do i just change:


Expand|Select|Wrap|Line Numbers
  1.  
  2.  If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
  3.  
  4.  
to


Expand|Select|Wrap|Line Numbers
  1.  
  2. if e.keychar = Microsoft.VisualBasic.chrW(50) then
  3.  
  4.  
or ......
Aug 31 '07 #10
Yep looks like you have the idea... I said in my post that the code handled text box presses, but what you have written will allow for keypresses on whole form.

You can use any number in brackets for a keycode, there are lists of what the values are online, I think there is one in MSDN if you just search "keycodes"

Glad I could help!

Martin
Sep 3 '07 #11

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

Similar topics

3
by: Peter Verburgh | last post by:
Is there an easy way to capture the keypress - keydown events from a LABEL control ? Standard the control doesn't handle these events. The label control inherits from the control class , and this...
0
by: Coder | last post by:
hi, i am using a c# windows application. i want to handle some keypress events like ctrl+A, shift+enter, etc.. is it easy to handle only one keypress; as KeyPressEventArgs e;... e.KeyPress. ...
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
4
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
3
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I...
4
by: Michael Green | last post by:
Hi, In VB6 you used to be able to modify keys as they were pressed in the KeyPress event e.g. change it uppercase, remove certain characters etc. How do I do this in .NET ? Regards Michael
2
by: Finn Stampe Mikkelsen | last post by:
Hi Can i handle keypress on a form-level, with no regard to wath control has focus and which tabcontrol is visible??? If so, could you include sample code with weight on F-keys and key-codes...
0
by: Terry Reedy | last post by:
rishi pathak wrote: Does not work on Windows, at least with 3.0, as tty fails trying to import termios. There, use msvcrt module "msvcrt.kbhit() Return true if a keypress is waiting to be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.