Hi, I'm new to .NET framework. In the past I've used Borland and trying to learn visual c++.NET is a challenge. I'm not familar with MFC, so I'm diving straight into .NET. I have not found any good beginner/intermediate books.
Anyway, I'm trying to convert an entry into a Textbox (Textbox1->Text) to an int and want a simple way to check and see if the user entered a number or an alphabetic expression. I know I can convert using
int x;
x = System::Convert::ToInt32(Textbox1->Text);
if the user enters a number. Problems though if you enter a letter.

Textbox
Meylum
On Key Press would probably be the best choice to limit the number of bytes the <b>Text</b>Box can take as proper inputs. Remember, Microsoft gives developers bare necessities to develop the applications they desire to or are required to.
This is probably what you're looking for.
// in InitializeComponents, add this event handler.
this.textBox1.KeyPress +=
new System.Windows.Forms.KeyPressEventHandler(this.NumbericTextValidator);
// now this is the event handler's method.
private void NumbericTextValidator(
object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if ("0123456789".IndexOf(e.KeyChar) > 0)
e.Handled = false;
else
e.Handled = true;
}
edited:
by the way, for those that swear by the IsNumeric method of using int or double.parse.. this way is much faster and uses less resources when working with non decimal related validations.
;)
phox
if (".0123456789".IndexOf(e.KeyChar) > -1)
ginee
Jim Vinsel
Is there any thrid party code for numeric input in visual c++.net I have actually seen code where the string object is pasted to the clipboard just so the numeric data can be pulled back and used Surely Microsoft did not intend this This just doesn't that difficult of a problem to solve and yet I am no closer to solving it than when I started.