473,387 Members | 1,388 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,387 software developers and data experts.

keypress problem

I have a sample:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar<255)
e.Handled = true;
}

above code can prevent ASCII code when I pressed.

but I wonder how I can prevent Chinese characters Key in ? because:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar>255)
e.Handled = true;
}
can not work properly when I key in. What can i do ?

B.Rgds
Nov 15 '05 #1
1 1774
> I have a sample:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar<255)
e.Handled = true;
}

above code can prevent ASCII code when I pressed.
Actually, there are only 128 ASCII characters.

but I wonder how I can prevent Chinese characters Key in ? because:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar>255)
e.Handled = true;
}
can not work properly when I key in. What can i do ?


I would suggest using one of the static methods in the System.Char class,
for example:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetter(e.KeyChar))
e.Handled = true;
}
This will block all Unicode characters that are classified as Letter. There
are
also IsDigit(), IsPunctuation() and so on.

- Magnus
Nov 15 '05 #2

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

Similar topics

12
by: Trevor Fairchild | last post by:
I'm writing a program that is designed for quick navigation using specific buttons on the keyboard. In doing this, I have added a KeyPress event for every control on the form to intercept the key...
2
by: Christian | last post by:
Hello, As the subject says it, is there a way to simulate a special keypress in JS ? In my case, on loading an HTML page, i'd like to set the cursor at the end of the input text of an <input...
1
by: Thomas | last post by:
Hey y'all, I'm using firebird 0.7 and developed some kind of inline editing with java script. Therefore I used the keypress event listener. The problem is that I can only enter one character...
3
by: Keith Smith | last post by:
Whenever a Keydown EventHandler is processed the computer never continues on to process the KeyPress EventHandler. Is there a way to stop this? My goal is to be able to detect these keys from...
2
by: rege | last post by:
Hi, I have two applications developed in C# say A and B. When user presses key "L" with applicaition A active , it causes a keypress event which causes application B to run. Application A then...
6
by: Niksa Baldun | last post by:
Hi, I am trying to capture data from magnetic stripe reader which is connected via keyboard interface (therefore indistinguishable from normal keyboard input). Basically, I am doing the...
2
by: KC | last post by:
I'm trying to build a simple text editor in part of my app. Right now I'm just testing the basics of the KeyPress event handler. The code is basic...real simple. I'm just testing stuff - Private...
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...
12
by: Todd Sparks | last post by:
I am using Visual Studio 2003 to develop a windows application in which I allow the users to just press Enter, while the focus is on a textbox, in order to perform a search. My problem is that...
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...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.