Handle the Validating event to parse the Text in the MaskedTextBox into float type, if convertion faild, cancel the validating, which prevent the fucus moving out of the MaskesTextBox.
Code Snippet
maskedTextBox1_Validating(object sender, CancelEventArgs e)
{
try
{
float.Parse(this.maskedTextBox1.Text);
}
catch
{
e.Cancel = true;
}
}
Handle the Validating event to parse the Text in the MaskedTextBox into float type, if convertion faild, cancel the validating, which prevent the fucus moving out of the MaskesTextBox.
Code Snippet
maskedTextBox1_Validating(object sender, CancelEventArgs e)
{
try
{
float.Parse(this.maskedTextBox1.Text);
}
catch
{
e.Cancel = true;
}
}
i tried it but it didnt seem to do what i wanted it to do ...myquestion now is
i have a set button on my window and when the user clicks a wrong format ... other than the masked format i want to catch the error
say for example i have this code write..
private void setvalue_Click(object sender, EventArgs e)
{
string a = txBxP4.Text;
MessageBox.Show(a);
}
i have already set the masked text boxes to only accept input like this "##.#"
now i want to display an error message each time he enters something like 0_.0
I am sorry for the dumb questions .. i am new to programming ... any help will be very much appreciated ..
thanks
|