我应该为学校编写一个将英寸转换为英尺,将英尺转换为码等的代码。这是通过从两个列表框中选择一个或另一个来完成的:“ from”和“ two”。
但是,我完全不知道该怎么做。我已经尝试了下面列出的代码,但是除此之外,我的线索是零。
我基本上想从列表框中获取两个值,根据列表框中选择的内容为其分配一个方法,然后根据用户的输入对其进行转换。我需要帮助!
namespace Distance_Converter
{
public partial class frmDistanceConverter : Form
{
int inches = 1;
int feet = 12;
int yards = 36;
public frmDistanceConverter()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnConvert_Click(object sender, EventArgs e)
{
double feettoInch = feet / 12 * 12;
double feettoYard = feet / 3; // feet conversions
double feettoFeet = feet;
double yardtoYard = yards;
double yardtoInch = yards / 1; // yard conversions
double yardtoFeet = yards / 12;
double inchtoYard = inches / 36;
double inchtoInch = inches;
double inchtoFeet = inches / 12;
double totalConversion = double.Parse(txtDistance.Text);
}
}
}