帮助从文本框到列表框进行计算 [英] Help in getting calculation from textbox to listbox
问题描述
我希望有人可以帮助我。我是C#的新手,我的任务是完成任务。这涉及为将在主窗体中显示的计算类提供代码。文本输入文本框并显示在 列表框。数字
由按键事件填充,以在列表框中显示为列表。按#按钮将显示小计和= 总计。
I hope someone can help me. I'm very new in C# and has been tasked to do an assignment. This involves witing a code for a calculation class that will show in the mainform. The text is entered in a Textbox and displayed in listBox. Numbers are populated by a keypress event to appear as a list in the listbox. Pressing the # button will give the subtotal and = the Total.
它将如下所示。关于如何做到这一点的任何意见都将受到高度赞赏。提前致谢。
It will look like the below. Any inputs on how I can do this will be greately appreciated. Thanks in advance.
推荐答案
这是一个基本模式,用于总计和注释我没有使用已经存在的文本框事件。请注意确定什么是子总数。
Here is a basic pattern to work from for total and note I did not use textbox events as you have that already. Note sure what constitutes sub total.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(textBox1.Text))
{
int value = 0;
if (int.TryParse(textBox1.Text, out value))
{
listBox1.Items.Add(value);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
var data = from item in listBox1.Items.Cast<string>() select Convert.ToInt32(item);
label1.Text =
" Sum:{data.Sum()}" ;;
}
}
}
"Sum: {data.Sum()}"; } } }
这篇关于帮助从文本框到列表框进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!