Question
Event Handler to clear textboxes I'm trying to create an event handler to clear the Results textbox if the text in any other box is
Event Handler to clear textboxes
I'm trying to create an event handler to clear the "Results" textbox if the text in any other box is changed. It has to be a wiring event and I am unsure exactly how to do this.
Here is my code (it works flawlessly minus the clearing Results):
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace Lab6_7_200 { public partial class Lab6 : Form {
public Lab6() { InitializeComponent(); }
private void Lab6_Load(object sender, EventArgs e) {
}
private void btnCalculate_Click(object sender, EventArgs e) { decimal value1 = Convert.ToDecimal(this.txtValue1.Text); //convert text to decimal decimal value2 = Convert.ToDecimal(this.txtValue2.Text); //convert text to decimal string operator1 = Convert.ToString(this.txtOperator.Text); //convert operator input to string decimal totalResult = this.GetResult(value1, value2, operator1); //sending values to method and calling it txtResult.Text = "" + totalResult; //writing into result textbox }
private void btnExit_Click(object sender, EventArgs e) { this.Close(); //closing the program }
private decimal GetResult(decimal value1, decimal value2, string operator1) //creating the method { decimal result = 0;
if (operator1 == "x") //determining the operator to be used { result = value1 * value2; //multiplication of the values }
else if (operator1 == "+") { result = value1 + value2; //addition of the values }
else if (operator1 == "-") { result = value1 - value2; //subtraction of the values }
else if (operator1 == "/") { result = value1 / value2; //division of the values }
return result; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started