Add values of textboxes when leaving the field [closed]

2

I have a form with three TextBoxes where the user will type any value and a Label where I want to show the result of the sum of these values.

However, I'd like to add the contents of these TextBoxes without having to click a button. I mean, while I'm filling in the TextBoxes , the values are being summed and the sum is shown in Label .

    
asked by anonymous 22.09.2015 / 23:42

1 answer

0
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void fazOqVcQuer()
    {
        try
        {
            label1.Text =
            (Convert.ToDecimal(textBox1.Text)
            +
            Convert.ToDecimal(textBox2.Text)
            +
            Convert.ToDecimal(textBox3.Text)).ToString();
        }
        catch (Exception)
        {
        }  
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        fazOqVcQuer();
    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {
        fazOqVcQuer();
    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {
        fazOqVcQuer();
    }
}

Hello, my friend. There are several ways to do this. Since you are starting out, understand this "very good" code. replace the values "textBox1", "textBox2" and "textBox3" with the name of yours, etc.

    
23.09.2015 / 02:19