Click here to Skip to main content
15,894,343 members
Home / Discussions / C#
   

C#

 
AnswerRe: Do you know any VS 2003 to VS.NET project converter? Pin
Heath Stewart18-Jul-03 22:34
protectorHeath Stewart18-Jul-03 22:34 
GeneralRe: Do you know any VS 2003 to VS.NET project converter? Pin
Steuernol19-Jul-03 0:50
Steuernol19-Jul-03 0:50 
AnswerRe: Do you know any VS 2003 to VS.NET project converter? Pin
Uwe Keim19-Jul-03 6:31
sitebuilderUwe Keim19-Jul-03 6:31 
Questionhow to connect??? Pin
don7cry18-Jul-03 20:46
don7cry18-Jul-03 20:46 
QuestionHow to use the KeyPress event Pin
kharr102718-Jul-03 17:03
kharr102718-Jul-03 17:03 
AnswerRe: How to use the KeyPress event Pin
Nick Parker18-Jul-03 19:16
protectorNick Parker18-Jul-03 19:16 
GeneralRe: How to use the KeyPress event Pin
kharr102720-Jul-03 9:28
kharr102720-Jul-03 9:28 
GeneralRe: How to use the KeyPress event Pin
Nick Parker20-Jul-03 17:43
protectorNick Parker20-Jul-03 17:43 
kharr1027 wrote:
private void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar < 'a'||e.KeyChar > 'z')&& e.KeyChar != '\b')
e.Handled = true;
}


A few things, first of all I just re-tried the code example I gave you and it does work, however I noticed in the code example you listed you have Form1_KeyPress which appears that you have an event handler registered for the KeyPress event of a Form, not a TextBox. Make sure whatever the name of your textbox that you add to your form includes the following event/delegate assignment (for this example the name of my textbox is simply the default of textBox1):

this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);


then the following will work to only allow alphabetic characters, space and backspace entries:

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
       // Allow only alpha characters   
	base.OnKeyPress(e);   
        if (Char.IsLetter(e.KeyChar) || Char.IsPunctuation(e.KeyChar)        
	    || Char.IsSeparator(e.KeyChar) || Char.GetNumericValue(e.KeyChar) == -1)      
            e.Handled = false;   
	else       
	    e.Handled = true;
}


-Nick Parker
AnswerRe: How to use the KeyPress event Pin
Bo Hunter20-Jul-03 11:49
Bo Hunter20-Jul-03 11:49 
QuestionUpDown control ValueChange Problem? Pin
azusakt18-Jul-03 15:29
azusakt18-Jul-03 15:29 
QuestionCreate a managed array from a pointer? Pin
Josh Martin18-Jul-03 15:11
Josh Martin18-Jul-03 15:11 
AnswerRe: Create a managed array from a pointer? Pin
Jim Stewart18-Jul-03 16:07
Jim Stewart18-Jul-03 16:07 
GeneralRe: Create a managed array from a pointer? Pin
Josh Martin21-Jul-03 7:23
Josh Martin21-Jul-03 7:23 
Generaldatagrid row problem Pin
mdolby18-Jul-03 12:26
mdolby18-Jul-03 12:26 
GeneralRe: datagrid row problem Pin
Mazdak19-Jul-03 11:29
Mazdak19-Jul-03 11:29 
Generalconnect c# web service Pin
colin mcadam18-Jul-03 3:34
colin mcadam18-Jul-03 3:34 
GeneralRe: connect c# web service Pin
Ista21-Jul-03 17:18
Ista21-Jul-03 17:18 
GeneralC# Web Service Client Pin
hwen18-Jul-03 3:14
hwen18-Jul-03 3:14 
GeneralC # development with OWC &amp; XP Pia's Pin
Member 47499718-Jul-03 3:04
Member 47499718-Jul-03 3:04 
QuestionHow to control the number of instances of a application Pin
Ivan Fernandez18-Jul-03 2:57
Ivan Fernandez18-Jul-03 2:57 
AnswerRe: How to control the number of instances of a application Pin
Kastro18-Jul-03 3:53
Kastro18-Jul-03 3:53 
GeneralActivator Class Pin
vikramlinux18-Jul-03 2:10
vikramlinux18-Jul-03 2:10 
GeneralRe: Activator Class Pin
John Fisher18-Jul-03 4:32
John Fisher18-Jul-03 4:32 
GeneralDataAdapter and StoredProcedure Pin
totig18-Jul-03 1:18
totig18-Jul-03 1:18 
GeneralRe: DataAdapter and StoredProcedure Pin
Kant19-Jul-03 16:42
Kant19-Jul-03 16:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.