Dear Sir,
I am using following codes on EVERY textbox.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { char ch = e.KeyChar; decimal x; if (ch == (char)Keys.Back) { e.Handled = false; } else if (!char.IsDigit(ch) && ch != '.' || !Decimal.TryParse(textBox1.Text + ch, out x)) { e.Handled = true; } } private void textBox1_Leave(object sender, EventArgs e) { if (textBox1.Text == "") { MessageBox.Show("Please enter Num 1"); return; } else { textBox1.Text = Convert.ToDecimal(textBox1.Text).ToString("#,##"); } }
In this way I have to waste much time and form space.
Is there any other way to use a routine on InitilizeCompent to handle all textboxes?
Please help