简体   繁体   English

将多个项目添加到listBox-仅做一些工作

[英]Adding multiple items to listBox - only some work

Currently covering GUI's, I want to write a program that takes two integers and puts them and their product in a listBox . 当前涉及GUI,我想编写一个程序,该程序接受两个整数并将它们及其乘积放入listBox Currently I have a textBox for each integer, and a button that adds them to the listBox . 目前,我为每个整数都有一个textBox ,以及一个将其添加到listBox的按钮。 There is then a third button that calculates the product and adds it to the listBox . 然后,第三个按钮将计算产品并将其添加到listBox The first two buttons work - but the third one does not - clicking the button doesn't do anything. 前两个按钮有效-但第三个按钮无效-单击该按钮不会执行任何操作。 Routing that button to a different listBox doesn't fix the error. 将该按钮路由到另一个listBox不能解决该错误。 My current code is below: 我当前的代码如下:

        private void button1_Click(object sender, EventArgs e)
    {
        int Int1;
        Int1 = int.Parse(textBox1.Text);
        listBox1.Items.Add(Int1);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        int Int2;
        Int2 = int.Parse(textBox2.Text);
        listBox1.Items.Add(Int2);
    }
    private void button3_Click(object sender, EventArgs e)
    {
        int Product;
        Product = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);
        listBox1.Items.Add(Product);
    }

I have also tried separately parsing textBox1.Text and textBox2.Text when finding Product, to no avail. 我也尝试过在找到产品时分别解析textBox1.TexttextBox2.Text ,但无济于事。

EDIT: this.button3.Click += new System.EventHandler(this.button3_Click); 编辑: this.button3.Click += new System.EventHandler(this.button3_Click); was missing from the code. 代码中丢失了。 It works now. 现在可以使用了。

this.button3.Click += new System.EventHandler(this.button3_Click); this.button3.Click + =新的System.EventHandler(this.button3_Click); was missing from the code. 代码中丢失了。 It works now. 现在可以使用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM