Reputation: 37
I was wondering if there was a way to clear the 'Result (txtBoxResult.Text)' text box if the user made any chances to any other other text boxes? Example: Let's say that after clicking submit I get my result and then I went on any of the other text boxes and added or deleted a number. How could I make the result go away right that moment?
Upvotes: 0
Views: 89
Reputation: 65534
In the other TextBoxes add TextChanged events that clear the original TextBox. Psuedo code:
txtBoxOps1.TextChanged += ClearOriginalTextBox;
...
void ClearOriginalTextBox(object sender, EventArgs e)
{
txtBoxResult.Text = string.Empty;
}
In form closing event don't for get to unsubscribe the events:
txtBoxOps1.TextChanged -= ClearOriginalTextBox;
Upvotes: 1
Reputation:
Well, I believe that can be easier, simply when the user click on the Submit Buttom you have to freeze the textboxs, so the user can't modify the textboxs again.
private void button1_Click(object sender, EventArgs e)
{
textBox1.Enabled = false;
}
Upvotes: 0
Reputation: 270758
There is an event called TextChanged
.
First, create an event handler to handle this event:
private void TextBoxTextChanged(object sender, EventArgs e) {
txtBoxResult.Text = "";
}
Next, subscribe to the event in the form's constructor:
txtBoxOp1.TextChanged += TextBoxTextChanged;
txtBoxOp2.TextChanged += TextBoxTextChanged;
txtBoxOperator.TextChanged += TextBoxTextChanged;
Upvotes: 2