Calculate change between textbox?

Asked

Viewed 824 times

1

Good evening, I have 3 textbox, and I would like someone to provide a code to help me, when I select the product on the grid the total value is added in textbox1, and so on, the more I add products , plus it adds up, well ... I would like a code that when typing the value received in the textbox2 , already appeared the change in textbox3, I do not know if I would have to use a keypress or something like that, so I need help.inserir a descrição da imagem aqui

  • Don’t just take the value of the textbox Valor total and decrease the textbox of valor recebido and play in the textbox Troco? You can use the event TextChanged to perform the calculation every time the user changes the value, or the event KeyDown, type user presses enter and performs the calculation. or can do when it loses focus of the textbox calculate.

  • Yes, but could you pass me the code ? I am a novice in c# I would have to be clearer so that I understand, if I can post a code I would like .

  • I enjoyed the keydown event, how can I do it ?

  • From a read on this link in the part where it says creating an event handler.

1 answer

1

A friendly example, that would be:

using System;
using System.Windows.Forms;

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

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MessageBox.Show("Enter key pressed");
            }
        }
    }
}

Remember, there is always official documentation to be consulted:

https://msdn.microsoft.com/en-us/library/system.windows.controls.textbox.onkeydown(v=vs.95). aspx

  • Ok, this event I do in the paid value textbox, but I don’t need the code of the subtraction of values ? unhappy tbm do not know , could help me ?

  • Thanks Danilo, I got it with your code! hug

  • Thanks My Hat , helped me a lot too! hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.