In this tutorial we are going to make a Temperature converter which can convert Celsius to Fahrenheit in C# Form Application.
In this program we are extending Windows Form. For that we are going to use 1 Button ,2 textBox and 2 radioButtons.
We place components like on the following image.
Button Click Event:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
private void buttonConvert_Click(object sender, EventArgs e) { try { if (radiotoCelsius.Checked == true) { double c = Convert.ToDouble(txtC.Text); txtF.Text = Convert.ToString((c * 1.8) + 32); } if (radiotoFahrenheit.Checked == true) { double f = Convert.ToDouble(txtF.Text); txtC.Text = Convert.ToString((f - 32) / 1.8); } } catch (Exception) { MessageBox.Show("Please enter a number"); } } |
Hi, so I tried this and it says that there is an error. It won’t let me convert to a string in windows form
Please type the error. If you write the error, i, ll try to help you as soon as
You need to convert numeric values to strings using ToString() method. Please visit this link for details.
https://docs.microsoft.com/en-us/dotnet/api/system.convert.tostring?view=net-5.0