传递变量成另一种形式 [英] passing variables into another form
问题描述
我在开发C#一个Windows应用程序。我用三个小数变量:计数
,窄
和广
这基于一些计算,存储不同的值。
I am developing a windows app in c#. I have used three decimal variables: counter
, narrow
, and broad
which store different values based on some calculations.
在点击一个按钮,将显示一个消息框显示应用程序退出这三个小数值,然后..
On clicking a button, a message box is displayed showing these three decimal values and then the application exits..
现在我想添加有三个标签中,这些变量的值需要显示另一种形式。请解释一下,我怎么可以通过在未来的形式这些变量在各个标签中显示?
Now I want to add another form having three labels in which these variable values needs to be shown. Please explain, how can I pass those variables in the next form to display in individual labels?
推荐答案
创建新格式...
public class CalculationResultForm : Form
{
public CalculationResultForm(){}
public decimal Counter
{
set { labelCounter.Text = value.ToString(); }
}
public decimal Broad
{
set { labelBroad.Text = value.ToString(); }
}
public decimal Narrow
{
set { labelNarrow.Text = value.ToString(); }
}
private void OkButton_Click(object sender, EventArgs e)
{
// This will close the form (same as clicking ok on the message box)
DialogResult = DialogResult.OK;
}
}
那么你的现有表单按钮单击处理程序中...
Then within your existing form button click handler...
private void MyButton_Click(object sender, EventArgs e)
{
CalculationResultForm resultForm = new CalculationResultForm();
resultForm.Counter = _counter;
resultForm.Narrow = _narrow;
resultForm.Broad = _broad;
resultForm .ShowDialog();
Application.Exit();
}
这篇关于传递变量成另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!