编写一个摄氏温度与华氏温度之间的转换程序用命令按钮实现转换.即单击"转换华氏"按钮,则将摄氏温度转换为华氏温度;同样,单击"转换摄氏"按钮,则将华氏温度转换为摄氏温度.注:要使用
来源:学生作业帮助网 编辑:六六作业网 时间:2025/02/01 14:35:13
编写一个摄氏温度与华氏温度之间的转换程序用命令按钮实现转换.即单击"转换华氏"按钮,则将摄氏温度转换为华氏温度;同样,单击"转换摄氏"按钮,则将华氏温度转换为摄氏温度.注:要使用
编写一个摄氏温度与华氏温度之间的转换程序
用命令按钮实现转换.即单击"转换华氏"按钮,则将摄氏温度转换为华氏温度;同样,单
击"转换摄氏"按钮,则将华氏温度转换为摄氏温度.
注:要使用的转换公式是f=9/5*c+32 其中f为华氏温度 c为摄氏温度
编写一个摄氏温度与华氏温度之间的转换程序用命令按钮实现转换.即单击"转换华氏"按钮,则将摄氏温度转换为华氏温度;同样,单击"转换摄氏"按钮,则将华氏温度转换为摄氏温度.注:要使用
使用VS的Windows 应用程序代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class MainForm :Form
{
//f=9/5*c+32,其中f为华氏温度,c为摄氏温度
double f,c = 0.00;
public MainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender,EventArgs e)
{
}
private void btnH_Click(object sender,EventArgs e)
{
if (this.txtOld.Text == "")
{
this.txtOld.Focus();
MessageBox.Show("请输入温度!");
}
else
{
try
{
if (((Button)sender).Name == "btnH")
{
f = double.Parse(this.txtOld.Text);
this.txtNew.Text = "" + (f - 32) * (5.0 / 9);
}
if (((Button)sender).Name == "btnS")
{
c = double.Parse(this.txtOld.Text);
this.txtNew.Text = "" + ((9.0 / 5) * c + 32);
}
}
catch (Exception)
{
MessageBox.Show("请输入正确信息!");
this.txtOld.Text = "";
this.txtOld.Focus();
}
}
}
}
}