Green Fuze
April 24th, 2005, 05:17 AM
Hey everybody!
I want to restrict a certain characters for edit box, I mean that
in a specific edit box the user will be able to type only numbers of characters.
is there a certain method for something like this???
lior6543
April 24th, 2005, 06:41 PM
private: System::Void textBox_Validating( System::Object * sender,
System::ComponentModel::CancelEventArgs * e )
{
String* errorMsg;
if( !ValidNumber(textBox->Text, &errorMsg) )
{
// Cancel the event and select the text to be corrected by the user.
e->Cancel = true;
textBox->Select(0, textBox->Text->Length);
// Set the ErrorProvider error with the text to display.
//errorProvider->SetError(textBox, errorMsg);
MessageBox::Show( errorMsg );
}
}
public: bool ValidNumber(String *numstring, String **errorMessage)
{
double num;
if (numstring->Length == 0)
{
*errorMessage = S"A number is required.";
return false;
}
else
{
try
{
num = Convert::ToDouble(numstring);
return true;
}
catch (Exception *exp)
{
*errorMessage = S"Entry cannot be converted to a real number";
return false;
}
}
}
Green Fuze
April 24th, 2005, 09:57 PM
thanks lior!