带有sum的文本框值以其他形式显示 [英] textbox values with sum display in other form

查看:60
本文介绍了带有sum的文本框值以其他形式显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如果我在下面的form1中的textbox1中输入值

1

2

3

4

i使用textbox2作为textbox1的总和

textbox1值不修复4个数字它可能是7或者10无论用户输入什么输入



所以我想得到你的显示用户输入值的帮助,其他形式的总和2

喜欢

1

2

3

4

----

10

----

plz帮助代码



if i enterd values in textbox1 in form1 like below
1
2
3
4
i used textbox2 for sum of textbox1
textbox1 value not fix 4 numers it may be 7 or 10 whatever user enterd inputs

so i want to get help for your for display user enterd values with sum in other form2
like
1
2
3
4
----
10
----
plz help for code

推荐答案

public class Form1 : Form
{
    private TextBox textBox1 = new TextBox();

    private Form2 form2 = new Form2();

    public Form1()
    {
        this.textBox1.Multiline = true;
        this.textBox1.Height = 100;
        this.textBox1.TextChanged += this.textBox1_TextChanged;

        this.Controls.Add(this.textBox1);
        this.Load += this.Form1_Load;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        form2.Show();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        int sum = 0;

        foreach (string s in this.textBox1.Lines)
        {
            int v;

            if (int.TryParse(s, out v))
            {
                sum += v;
            }
        }

        form2.Sum = sum.ToString();
    }
}







public class Form2 : Form
{
    private TextBox textBox2 = new TextBox();

    public Form2()
    {
        this.Controls.Add(this.textBox2);
    }

    public string Sum
    {
        set { this.textBox2.Text = value; }
    }
}


这篇关于带有sum的文本框值以其他形式显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆