1、开发一个窗体应用程序,窗体上能接收华氏温度或者摄氏温度,点击相应按钮可以相互转换。 要求转换后的华氏温度或者摄氏温度保留小数点后3位,程序中要有异常处理结构。
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace Myform1 11 { 12 public partial class Form1 : Form 13 { 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 private void label1_Click(object sender, EventArgs e) 20 { 21 22 } 23 24 private void button1_Click(object sender, EventArgs e) 25 { 26 try 27 { 28 textBox2.Text = htc(textBox1.Text).ToString("f3"); 29 } 30 catch (Exception ex) 31 { 32 Text = ex.Message; 33 } 34 } 35 36 private void button2_Click(object sender, EventArgs e) 37 { 38 try 39 { 40 textBox1.Text = cth(textBox2.Text).ToString("f3"); 41 } 42 catch (Exception ex) 43 { 44 Text = ex.Message; 45 } 46 } 47 48 public double htc( double x ){ 49 return (x - 32) * 5 / 9; 50 } 51 52 public double htc(string s) 53 { 54 double x = double.Parse(s); 55 return (x - 32) * 5 / 9; 56 } 57 58 public double cth(double x) 59 { 60 return (x * 9 / 5) + 32; 61 } 62 public double cth(string s) 63 { 64 double x = double.Parse(s); 65 return (x * 9 / 5) + 32; 66 } 67 68 } 69 }