Text box - masked edit

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

Is there a way to put making on a text box . My issue is that I have to
ensure that users can only enter a number no greater than 1.25 and no less
than .010. Additionally, I need to ensure that they can only enter numbers
and decimals (which I have already created event handlers to do).
 
John,

Assuming that only numbers are allowed, during focus leave event, put this
code

private void textbox1_Leave(object sender, System.EventArgs e)
{

try
{
//convert to double
double val = Convert.ToDouble(textbox1.text);
//validate the ranges.
if((val >1.25) || (val < 0.10))
{
MessageBox.Show("Invalid entry");
textbox1.focus();
}
}
catch
{
MessageBox.Show("Invalid entry");
textbox1.focus();
}
}
 
Back
Top