How to sum a two number from two different textbox without clicking the button the sum will automatically displayed in the label
protected void button1(object sender, EventArgs e)
{
double a, b, product;
a = double.Parse(txtt1.Text);
b = 15;
product = a * 15;
lbl_.Text = Convert.ToString(product);
2
Answers
Use the events that are designed for such purposes. If you even want to set default values and to show a sum of them, you can do this in the show event of your form like this:
Of course, this code is not really what you will do, it’s just to demonstrate how to do such things.
When one of the values within the other checkboxes has changed, you can rebuild the sum and display it using the text changed event. Something like this:
Again, just the idea, no real code. Of course, you should use the sender within the events.
Consider using a class setup with change notification using
INotifyPropertyChanged
and in your form data binding to, in this case two properties with a third property for the result.Here when values change in the form the label will reflect Value1 * Value2.
In the form, setup a key press event for two TextBox controls to allow only double.
Use data binding for two TextBox and one Label for the results of the two TextBox controls.