esposito Posted November 20, 2003 Posted November 20, 2003 Hello, everybody. I have been studying the syntax of VB.NET not for a long time and I'm trying to convert into this new language the most important functions I used to implement in VB6. Can anybody tell me the equivalent of the VB6 "SendKeys" statement under VB.NET? In other words, do you know how to simulate the pressure of the keyboard keys? An example in VB6 could be If KeyAscii = 13 Then SendKeys "{Tab}" Do you know how to "translate" the statement above into VB.NET? Thanks in advance for your help. Quote Pasquale Esposito Perugia - Italy http://www.geocities.com/espositosoftware
esposito Posted November 22, 2003 Author Posted November 22, 2003 PROBLEM SOLVED, at least partially. I still need to know the equivalent of KeyAscii = 0 that, in VB6, allows you to cancel the pressure of a keyboard key. Any suggestions? Hello, everybody. I have been studying the syntax of VB.NET not for a long time and I'm trying to convert into this new language the most important functions I used to implement in VB6. Can anybody tell me the equivalent of the VB6 "SendKeys" statement under VB.NET? In other words, do you know how to simulate the pressure of the keyboard keys? An example in VB6 could be If KeyAscii = 13 Then SendKeys "{Tab}" Do you know how to "translate" the statement above into VB.NET? Thanks in advance for your help. Quote Pasquale Esposito Perugia - Italy http://www.geocities.com/espositosoftware
Administrators PlausiblyDamp Posted November 22, 2003 Administrators Posted November 22, 2003 to achieve the same result in a textbox use... Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress e.Handled = True End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
esposito Posted November 22, 2003 Author Posted November 22, 2003 Thanks, PlausiblyDamp, you have solved my problem. I just wanted to prevent the users from pressing any keys different from numbers, giving them the possibility of using Backspace to make corrections and the Tab or Enter key to move the focus to another object. This is the code I have written: Private Sub txtNumbersOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoloNumeri.KeyPress 'The user can press Enter. If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then e.Handled = False MsgBox("You pressed Enter.") Exit Sub End If 'The user can press Backspace to make corrections. If e.KeyChar = Microsoft.VisualBasic.ChrW(8) Then e.Handled = False Exit Sub End If 'The user can press Tab. If e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then e.Handled = False Exit Sub End If 'The user is not allowed to type in letters. If e.KeyChar <> "1" And e.KeyChar <> "2" And e.KeyChar <> "3" And e.KeyChar <> "4" And e.KeyChar <> "5" And e.KeyChar <> "6" And e.KeyChar <> "7" And e.KeyChar <> "8" And e.KeyChar <> "9" And e.KeyChar <> "0" Then e.Handled = True MessageBox.Show("Please use only numbers.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If End Sub My only doubt is this: does the statement Microsoft.VisualBasic.ChrW(8) etc. refer to a DLL that could not be supported by implementations of the .NET platform for different operating systems? (I'm thinking about the Mono Project) Is there any other statement I could use instead of Microsoft.VisualBasic.ChrW(8) to refer to the Enter key, Backspace and Tab? TIA Quote Pasquale Esposito Perugia - Italy http://www.geocities.com/espositosoftware
*Gurus* Derek Stone Posted November 22, 2003 *Gurus* Posted November 22, 2003 [msdn]System.Text.Encoding[/msdn].GetChars() Quote Posting Guidelines
Darc Posted November 22, 2003 Posted November 22, 2003 I use Select Case in KeyPresses myself, looks better and easier to understand. Btw, Chr() is the function I use for getting Chars, here's what I got: Private Sub txtNumbersOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoloNumeri.KeyPress Select Case e.KeyChar 'The user can press Enter. Case Chr(13) e.Handled = False MsgBox("You pressed Enter.") Exit Sub 'The user can press Backspace to make corrections. Case Chr(8) e.Handled = False Exit Sub End If 'The user can press Tab. Case Chr(9) e.Handled = False Exit Sub End Select 'The user is not allowed to type in letters. If e.KeyChar <> "1" And e.KeyChar <> "2" And e.KeyChar <> "3" And e.KeyChar <> "4" And e.KeyChar <> "5" And e.KeyChar <> "6" And e.KeyChar <> "7" And e.KeyChar <> "8" And e.KeyChar <> "9" And e.KeyChar <> "0" Then e.Handled = True MessageBox.Show("Please use only numbers.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If End Sub Quote
esposito Posted November 22, 2003 Author Posted November 22, 2003 Thanks, Darc. You're right, it looks better and easier than the code I used. I use Select Case in KeyPresses myself, looks better and easier to understand. Btw, Chr() is the function I use for getting Chars, here's what I got: Private Sub txtNumbersOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoloNumeri.KeyPress Select Case e.KeyChar 'The user can press Enter. Case Chr(13) e.Handled = False MsgBox("You pressed Enter.") Exit Sub 'The user can press Backspace to make corrections. Case Chr(8) e.Handled = False Exit Sub End If 'The user can press Tab. Case Chr(9) e.Handled = False Exit Sub End Select 'The user is not allowed to type in letters. If e.KeyChar <> "1" And e.KeyChar <> "2" And e.KeyChar <> "3" And e.KeyChar <> "4" And e.KeyChar <> "5" And e.KeyChar <> "6" And e.KeyChar <> "7" And e.KeyChar <> "8" And e.KeyChar <> "9" And e.KeyChar <> "0" Then e.Handled = True MessageBox.Show("Please use only numbers.", "Invalid data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If End Sub Quote Pasquale Esposito Perugia - Italy http://www.geocities.com/espositosoftware
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.