c#中的计算按钮不起作用

时间:2015-02-08 16:49:00

标签: c#

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)13) 
      {  
            if(textBox1.Text !="")
        {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text="";
        }
      }
 }

    private void button1_Click(object sender, EventArgs e)
    {
        int i, n;
        double x, m;
        n = listBox1.Items.Count;
        m = 0;
        for (i=0;i<n;i=i++)
    {
            x=Convert.ToInt32(listBox1.Items[i]);
            m = m + 1;
       }   
        textBox2.Text=Convert.ToString(m);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox1.Items.RemoveAt(listBox1.SelectedIndex);
    }
}
    }
这应该是一个计数周期,非常简单,这一切都是我非常重要的学校作业请帮助当我点击button1它冻结我的电脑一分钟然后我需要去停止调整其他一切工作完美请帮助我这对我来说非常重要

1 个答案:

答案 0 :(得分:1)

非常感谢你帮助我把jus i ++,现在看起来它正在发挥作用。]

     private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)13) 
      {  
            if(textBox1.Text !="")
        {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text="";
        }
      }
 }

    private void button1_Click(object sender, EventArgs e)
    {
        int i, n;
        double x, m;
        n = listBox1.Items.Count;
        m = 0;
        for (i=0;i<n;i++)
    {
            x=Convert.ToDouble(listBox1.Items[i]);
            m = m + x;
       }   
        textBox2.Text=Convert.ToString(m);
    }

    private void button2_Click(object sender, EventArgs e)
    {
        listBox1.Items.RemoveAt(listBox1.SelectedIndex);
    }
}
    }