コード例 #1
0
 private void btnConvert_Click(object sender, EventArgs e)
 {
     var client = new WebService1SoapClient();
     string from = cbxFrom.SelectedItem.ToString();
     string to = cbxTo.SelectedItem.ToString();
     float value;
     if (!Single.TryParse(txtValue.Text, out value))
     {
         MessageBox.Show("Please enter a valid temperature.", "Invalid Temperature");
     }
     if (from == "Celsius" && to == "Farenheit")
     {
         txtResult.Text = client.CtoF(value).ToString();
     }
     if (from == "Farenheit" && to == "Celsius")
     {
         txtResult.Text = client.FtoC(value).ToString();
     }
     if (from == "Celsius" && to == "Kelvin")
     {
         txtResult.Text = client.CtoK(value).ToString();
     }
     if (from == "Kelvin" && to == "Celsius")
     {
         txtResult.Text = client.KtoC(value).ToString();
     }
     if (from == "Farenheit" && to == "Kelvin")
     {
         txtResult.Text = client.FtoK(value).ToString();
     }
     if (from == "Kelvin" && to == "Farenheit")
     {
         txtResult.Text = client.KtoF(value).ToString();
     }
     if (from == to)
     {
         txtResult.Text = txtValue.Text;
     }
 }