I am new to c# and using windows forms.
I have 2 textboxes textbox1
and textbox2
.
Lets say textbox1 has a value of 22, when I click on textbox2, the value in textbox1 should change to double (22.00).
textbox1.text = "22";
private void textBox2_MouseClick(object sender, MouseEventArgs e)
{
// convert the value in textbox1 to double .
}
private void textBox2_MouseClick(object sender, MouseEventArgs e)
{
// TODO: handle exceptions
textBox1.Text = double.Parse(textBox1.Text).ToString("F2");
}
1) You can find the format strings here: https://msdn.microsoft.com/pl-pl/library/dwhawy9k(v=vs.110).aspx.
2) double.Parse(...)
can throw an exception: https://msdn.microsoft.com/pl-pl/library/fd84bdyt(v=vs.110).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With