|
-
September 12th, 2002, 02:41 PM
#4
Add this code to InitializeComponent() function:
this.TextBox.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.TextBox_KeyPress);
and this to the code:
private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar!=(char)8)&&(e.KeyChar!=(char)32)&&(!Char.IsDigit(e.KeyChar)) )
//the ASCII character code for SAPCE is 32 and BACKSAPCE is 8
{
e.Handled=true;
}
}
the above fn will allow only digits, space and backspace to be typed in the textbox.
Hope this helps.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|