问:如何从用户输入的文本框输入到第二个文本框来获得转换后的价值?
我不确定如何解决所犯的逻辑错误。
我只是将输入转换为新的权重并将该值放入第二个文本框。
这是我到目前为止的代码。
namespace Your_weight_on_Saturn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
var earthWeight = float.Parse(earthBox.Text);
// holds the formula to calculate and find the value.
var solve = (earthWeight / 9.81) * 10.44;
MessageBox.Show("Your weight on saturn is" + solve);
this.convertButton.Click += new EventHandler(button1_Click);
}
private void saturnBox_TextChanged(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:2)
要初始化求解的地方,只需将另一个TextBox的文本设置为Solve。像这样:
solve = (earthWeight / 9.81) * 10.44;
SecondTextBox.Text=solve.ToString(); // It will set text of Second TextBox to the value of solve
答案 1 :(得分:0)
将其简单地转换为浮点型
solve = (float) ((earthWeight / 9.81) * 10.44);