In this post, we will create an example that will convert Celsius degrees to Fahrenheit degrees. Let’s look at the form we need before we start our example
F=(C * 1.8) + 32
Let’s start our example by designing our form.
Codes to be written to Button1 for converting the value entered in TextBox1 (Celsius)
1 2 3 4 5 6 7 | private void button1_Click(object sender, EventArgs e) { double c = Convert.ToDouble(textBox1.Text); textBox2.Text = Convert.ToString((c * 1.8) + 32); } |
If you want to modify program as “Fahrenheit to Celsius”
1 2 3 4 | double f = Convert.ToDouble(textBox2.Text); textBox1.Text = Convert.ToString((f - 32) / 1.8); |