本文介绍了单位换算帮助-Windows Phone 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为将转换英里,米,公里的程序(Windows Phone 7)编写代码.
每当我尝试运行它时,它就会崩溃.我是新来的.
这是我的代码...我有3个文本框,而我要尝试做的是,如果我在任何一个框中输入一个数字,其他两个框将进行转换.
I''m trying to write code for a program(windows phone 7) that will convert miles, meters, kilometers.
Everytime I try to run it it crashes. I''m new at this.
Here is my code.... I have 3 text boxes and what I''m trying to do is if I put a number in any one box that the other two boxes will so the conversion.
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
decimal kilotoal;
decimal milettl;
decimal metttl;
kilotoal = Convert.ToDecimal(KilometersBlock.Text);
milettl = Convert.ToDecimal(txtmile.Text);
metttl = Convert.ToDecimal(MetreBlock.Text);
kilotoal = milettl*1.609m;
metttl = milettl * 1609.3m;
kilotoal = metttl / 1000m;
milettl = metttl * 0.00062137119m;
milettl = kilotoal * 0.6214m;
metttl = kilotoal * 1000m;
answer.Text= milettl.ToString();
answer.Text = metttl.ToString();
answer.Text = kilotoal.ToString();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
txtmile.Text = "";
KilometersBlock.Text = "";
MetreBlock.Text = "";
}
}
}
推荐答案
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txtMeter_TextChanged(object sender, EventArgs e)
{
if (flag)
{
try
{
txtKiloMeter.Text = String.Format("{0:###0.000}", (double.Parse(txtMeter.Text) / 1000));
}
catch (Exception)
{
txtKiloMeter.Text = "";
}
}
}
private void txtKiloMeter_TextChanged(object sender, EventArgs e)
{
if (!flag)
{
try
{
txtMeter.Text = String.Format("{0:###0.000}", (double.Parse(txtKiloMeter.Text) * 1000));
}
catch (Exception)
{
txtMeter.Text = "";
}
}
}
bool flag = false;
private void txtMeter_Enter(object sender, EventArgs e)
{
flag = true;
}
private void txtMeter_Leave(object sender, EventArgs e)
{
flag = false;
}
}
}
Sumant Kumar(软件工程师)
Sumant Kumar (Software Engineer)
这篇关于单位换算帮助-Windows Phone 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!