0

I am trying to make my text inside the box disappear when a new value is typed inside the box. I figured out how to make it disappear but my reset to default value no longer works. Which is the problem

I tried multiple += signs and if statements ideas but I am not sure how to make this work together.

private void BtnResetDefault_Click(object sender, EventArgs e)
{
    txtElapsedTime.Text = "2";
    txtCurrentAmount.Text = "25";
    txtInitalAmount.Text = "100";
}

private void TxtInitalAmount_TextChanged(object sender, EventArgs e)
{
    if (txtInitalAmount.Text.Contains("100") && txtElapsedTime.Text.Contains("2") && txtCurrentAmount.Text.Contains("25"))
    {
        txtElapsedTime.Text = "100";
        txtCurrentAmount.Text = "2";
        txtInitalAmount.Text = "25";
    }
    else if (txtCurrentAmount.Text != null)
    {
        txtInitalAmount.Text = "";
        txtElapsedTime.Text = "";
        txtCurrentAmount.Text = "";
    }
}

I want to have when the user types in a value in the text box all 3 text boxes disappear and when the user clicks the reset to default button the default text comes back inside the text boxes. Instead when I hit reset to default it stays the same.

theduck
  • 2,589
  • 13
  • 17
  • 23
Thomas
  • 65
  • 1
  • 10

1 Answers1

1

You can try to unsubscribe from event "txtInitalAmount.TextChanged", and then resubscribe to it.

private void BtnResetDefault_Click(object sender, EventArgs e)
{
    txtElapsedTime.Text = "2";
    txtCurrentAmount.Text = "25";
    txtInitalAmount.TextChanged -= txtInitalAmount_TextChanged;
    txtInitalAmount.Text = "100";
    txtInitalAmount.TextChanged += txtInitalAmount_TextChanged;
}

private void txtInitalAmount_TextChanged(object sender, EventArgs e)
{
    txtInitalAmount.TextChanged -= txtInitalAmount_TextChanged;
    txtElapsedTime.Text = "";
    txtCurrentAmount.Text = "";
    txtInitalAmount.Text = "";
}
大陸北方網友
  • 3,696
  • 3
  • 12
  • 37