Here we discuss the How to validate the TextBox with Currency value.For currency TextBox some Specifications are there,That are
1)TextBox takes only numeric values,
2)TextBox text align into Right side of the TextBox after Leaving the TextBox With ".00"
This is the common specification to every currency TextBox
Code for Currency Text Box:
we have to write this code in the Textbox KeyPressEvent
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(char.IsLetter(e.KeyChar))
{
e.Handled=true;
}
}
And one Specification is ".00" in right side of the text after leaving for these we write the code in the TextBox leaving Event,
See the below figure:
private void textBox1_Leave(object sender, EventArgs e)
{
double x;
double.TryParse(textBox1.Text, out x);
textBox1.Text = x.ToString(".00"); //adding the .00 every Currency data
textBox1.RightToLeft = RightToLeft.Yes; //set the data at right side of the textbox
}
I hope this code will Help you
1)TextBox takes only numeric values,
2)TextBox text align into Right side of the TextBox after Leaving the TextBox With ".00"
This is the common specification to every currency TextBox
Code for Currency Text Box:
we have to write this code in the Textbox KeyPressEvent
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(char.IsLetter(e.KeyChar))
{
e.Handled=true;
}
}
And one Specification is ".00" in right side of the text after leaving for these we write the code in the TextBox leaving Event,
See the below figure:
private void textBox1_Leave(object sender, EventArgs e)
{
double x;
double.TryParse(textBox1.Text, out x);
textBox1.Text = x.ToString(".00"); //adding the .00 every Currency data
textBox1.RightToLeft = RightToLeft.Yes; //set the data at right side of the textbox
}
I hope this code will Help you