【发布时间】:2016-06-06 04:13:12
【问题描述】:
我是 C# 的新手,正在学习我正在苦苦挣扎的课程。
任务是使用文本框值 (valuetextbox) 创建一个转换应用程序,并有 2 个保存英寸、英尺和码测量值的列表框。目标是根据在第一个列表框中选择的测量单位 (selectedinitialunit) 转换值,并根据在第二个列表框中选择的测量单位 (selectedconvertedunit) 在标签中张贴一个值。我错过了如何根据输入到 valuetextbox 中的值在我的 selectedinitialunit 和我 selectedconvertedunit 之间进行比较(数学)。
namespace Measurement_Conversion
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void convertedValueLabel_Click(object sender, EventArgs e)
{
}
private void exitButton_Click(object sender, EventArgs e)
{
Close();
}
private void resetButton_Click(object sender, EventArgs e)
{
valueTextBox.Text = "";
convertedValueLabel.Text = "";
DesiredUnitBox.SelectedIndex = -1;
InitialUnitBox.SelectedIndex = -1;
valueTextBox.Focus();
}
private void convertButton_Click(object sender, EventArgs e)
{
//Declare Variables
decimal initialvalue;
decimal convertedvalue;
string selectedInitialUnit;
string selectedConvertedUnit;
//Grab Initial Value
initialvalue = int.Parse(valueTextBox.Text);
//Determining Initial Unit has been selected.
if (InitialUnitBox.SelectedIndex != -1)
{
selectedInitialUnit = InitialUnitBox.SelectedItem.ToString();
}
else { MessageBox.Show("Please select an Initial Unit of measurement."); }
//Determining Desired Conversion Unit has been selected
if (DesiredUnitBox.SelectedIndex != -1)
{
selectedConvertedUnit = DesiredUnitBox.SelectedItem.ToString();
}
else { MessageBox.Show("Please select a desired conversion unit of measurement."); }
//Switch Statement
switch (selectedInitialUnit)
{
case "Inches":
convertedValueLabel.Text = ()
break;
case "Feet":
break;
case "Yards":
break;
}
}
}
}
我写在纸上的内容是这样说的——这不是代码,只是我的思考过程:
if selectedinitialunit = INCHES and selectedconvertedunit = INCHES
then messagebox.show("Please select a different selectedconvertedunit");
else selectedinitialunit = INCHES and selectedconvertedunit = FEET
then convertedvaluelabel.Text = initialvalue/12;
else selectedinitialunit = INCHES and selectedconvertedunit = YARDS
then convertedvaluelabel.Text = initialvalue/36;
对于其他选定的初始单位,依此类推。
非常感谢您的帮助,我希望我不会在这里到处乱跑。
提前谢谢你!
【问题讨论】: