Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys, am back.

First i need to thank you for the "regula expression" given to me ealier, it happily solved my problem.:thumbsup:

NOW, before sorting an array I get values from TextBox1.Text like(eg. 323,1,65,7,3,999,0,).

HOW can i disable the use of spaces in this control to restrict the user from giving unwanted spaces? I need only numbers and commas.:confused:

Thanks
Posted

I would look at using the KeyPress event on the textbox and set e.Handled=true if the key was a spacebar (e is the KeyPressEventArgs for the event handler). Your code might look something like this:
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
  e.Handled = e.KeyChar == ' ';
}
By setting Handled to true, this character won't be reflected in the textbox. BTW - please name your variables better than the default values that VS gives you. TextBox1 won't seem too bad to you now, but will you remember what it's for in 6 months time?
 
Share this answer
 
Comments
Member 12866151 23-Nov-16 5:26am    
Verrrrry nice
To add onto the answer above, the KeyPress event handler won't work unless you set KeyPreview to true. The KeyPreview property is on the Windows Form (click your form, look to the property box to the right, find KeyPreview, and set it to True).

Or you can manually add the following to the form constructor:
this.KeyPreview = true;
 
Share this answer
 
VB does not use a double equal sign to test for equality. It only uses a single equal sign. Try:
VB
e.Handled = (e.KeyChar = " ")

Also, it doesn't use semicolons to end lines.
 
Share this answer
 
Comments
nGrafix 6-Aug-10 19:26pm    
Reason for my vote of 5
solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900