473,500 Members | 1,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Restricting Keystrokes in VB .Net

H

In VB6 I used to trap by keycode on the keydown event and if the keystroke didn't fit into my criteria I would set the value of the keycode to 0 which would invalidate the keystroke. I noticed that the properties are readonly in .Net. How would I do the same as I used to in 6? I am doing the time honoured only allowing of numbers in a text box and don't seem to be getting right.

Thank you.
Nov 22 '05 #1
5 1957
KeyDown and check out the values of the 'e' the EventArgs..
"Robin" <an*******@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
HI

In VB6 I used to trap by keycode on the keydown event and if the keystroke didn't fit into my criteria I would set the value of the keycode to 0 which
would invalidate the keystroke. I noticed that the properties are readonly
in .Net. How would I do the same as I used to in 6? I am doing the time
honoured only allowing of numbers in a text box and don't seem to be getting
right.
Thank you.

Nov 22 '05 #2
Set the "handled" property to true to indicate that the event has been
handled.

Lloyd Sheen

"Robin" <an*******@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
Yes I know that I can trap the values but I cannot simply assign a 0 and override what the user typed as per version 6. The e.keycode value is read
only. If I want to change it after it has been typed I shall have to do
something different.
Thanks

Nov 22 '05 #3
Perhaps I am not being clear enough. If I say only want to allow a keyvalue = to the numeric set and somebody types a "G" which is 71 even if I set the handled property to true I still see a "G" in the textbox. I don't want the "G" to be there. I want to trap and disallow invalid keystrokes so that they never make it to the screen

Thanks
Nov 22 '05 #4
I understand what you are trying to do. We had lots of text boxes with
handlers in VB6 and the set the keyvalue = 0 was a common piece of code.

I am looking for code in dot.net that does this , I know I translated some
of our current code so it is around. Just cannot promiss when it will show
up. I am pretty certain it had to do with the "handled" property though.

Lloyd
"Robin" <an*******@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
Perhaps I am not being clear enough. If I say only want to allow a keyvalue = to the numeric set and somebody types a "G" which is 71 even if I
set the handled property to true I still see a "G" in the textbox. I don't
want the "G" to be there. I want to trap and disallow invalid keystrokes so
that they never make it to the screen.
Thanks

Nov 22 '05 #5
Put the code in the following (with your code)
What the below does is stop all keyboard activity so just add whatever you
want let through.
You will not be able to modify what is entered only stop what you deem
invalid.
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.Handled = True
End Sub
Lloyd

"Robin" <an*******@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
Perhaps I am not being clear enough. If I say only want to allow a keyvalue = to the numeric set and somebody types a "G" which is 71 even if I
set the handled property to true I still see a "G" in the textbox. I don't
want the "G" to be there. I want to trap and disallow invalid keystrokes so
that they never make it to the screen.
Thanks

Nov 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4965
by: Olli Piepponen | last post by:
Hi, I'm having a little problem catching keystrokes under Windows. I did a little research and found that with mscvrt.getch() one can cath a single key that is pressed. However this doesn't work...
5
454
by: Robin | last post by:
H In VB6 I used to trap by keycode on the keydown event and if the keystroke didn't fit into my criteria I would set the value of the keycode to 0 which would invalidate the keystroke. I noticed...
3
8938
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and...
5
2720
by: Lucas Tam | last post by:
Hi all, Has anyone done this before? Send client side keystrokes to an application from a webpapge? This maybe more of a Javascript question. In short, I have an application on the client's...
2
1625
by: zak | last post by:
I have some testing to do and I need to put a whole set of data in I want to Record and replay in a loop keystrokes. An idea
2
10151
by: Tim Diggle | last post by:
I'm trying to enter data into a database application running under Citrix ICA Client. I'm doing it from a VBA macro running under Microsoft Excel 2000 (although it may need to be backwardly...
3
5030
by: Gunnar Syren | last post by:
I'm trying to implement a macro feature in my application by recording and playing back keystrokes. At first I thought it would be enough to catch KeyDown in my main form, but I soon realized that...
1
3729
by: zanthor | last post by:
Ok... so call me crazy, but I have an idea and I'm looking for where to start... I want to write an application that catches keystrokes and then either redirects them to the in focus window or...
8
8689
by: sneddo | last post by:
Ok I am trying to do the above, I have got a script that will restrict the length but it requires the user to enter the field and hit a key, before it will work. This would normaly be find, but...
4
2289
by: Vighneswar | last post by:
Hi All Can anybody please suggest me in this regard that I need to capture the keystrokes on all the word processors (Ms Word, Excel .. Etc), text editors (Notepad .. Etc) and suggest nearer...
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3110
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.