【发布时间】:2015-03-30 06:57:11
【问题描述】:
大家好,我想知道有没有可能
Winform 项目
A.) 1~5 个组合框
B.) 1~5 个时间文本框(我将它们标识为 txtTime1 ~ txtTime5)
C.) 1~5 金额文本框(我将它们标识为例如 txtAmount1 ~ txtAmount5)
Items 1 ~ 5 (ComboBox 1-5 , txtTime 1-5, txtAmount 1-5) 将执行相同的功能。
答)
if (combobox1.SelectedValue.ToString() == "Regular")
{
x = 1.25;
}
else if (combobox1.SelectedValue.ToString() == "Double")
{
x = 2;
}
// Same Codes for ComboBox 2~5
B.)Textbox "txtTime(s)" 将持有一个 TextChange 事件,获取我们所说的组合框的值
if (txtTime.Text.Lenght > 0)
{
// Item Letter "C"
// value of "x" is equal to the above item
txtAmount.Text = (double.Parse(txtTime.Text) * x).ToString();
}
我只需要快速了解我将如何完成这项工作
提前致谢
编辑*
我能想到的只是一个快速的代码一个一个地调用它们
private Method1()
{ double x,base;
if (combobox1 = "Regular")
{ x = base * 1.25; }
if (combobox2 = "Regular")
{ x = base * 1.25; }
// so on
return x;
}
private txtTime1_TextChange(Event ****)
{
if (txtTime1.Text.Lenght > 0)
{ txtAmount1.Text = (Method1() * double.Parse(txtTime1.Text)).ToString();}
private txtTime2_TextChange(Event ****)
{
if (txtTime2.Text.Lenght > 0)
{ txtAmount2.Text = (Method1() * double.Parse(txtTime2.Text)).ToString();}
// and so on
【问题讨论】:
标签: c# wpf winforms visual-studio combobox