In my project there is an UserControl which includes a NumericUpDown ctrl, and its valid value range is from 10 to 100,
so if user inputs 200 in NumericUpDown ctrl, then its value will changed to 100 automatically after the focus changed to other ctrl, it looks a little bit curious for customer, because they may click the OK button after input 200 in the NumericUpDown ctrl, they need a message box that tells them the value they input is not in the range.
But the question is the value for NumericUpDown will change automatically after the focus changed if the value input is out of its range.
So how to implement this?
Sameh Serag, this is the code I have tested. I have add a button on the form but did nothing. The result for me is after I input 200 and click the button, only a messagebox with value 100 is shown. After I input 200 and press the tab key, it will only show a messagebox with the value 200 and the text value in NumericUpDown is changed to 100. So curious :-) Anyway thank you very much for your help! BTW, the .Net framework version is 2.0 with sp2 for me.
public partial class Form1 : Form
{
private TextBox txt;
public Form1()
{
InitializeComponent();
txt = (TextBox)numericUpDown1.Controls[1];
txt.Validating += new CancelEventHandler(txt_Validating);
}
void txt_Validating(object sender, CancelEventArgs e)
{
MessageBox.Show(txt.Text);
}
}