0
votes

I am working on a small project where I have 2 buttons and 2 panels. panel 1 has TextBox panel 2 has a different TextBox

And there are 2 buttons. When I press button1 panel2 will show, and when I press button2 panel1 will show. Now let say I type something in panel1's textbox I want when I move to panel2 and move back to panel1 the textbox to be empty, just like if I am running the form again. Here are my codes for the 2 buttons.

This is for the button that will show panel2

 private void ShowPanel2_Click(object sender, EventArgs e)
    {
        Panel Panel2Var = new Panel();
        Panel2Var = Panel2;
        Panel1.Hide();
        Panel2.Show();
    }

This is the button that will show panel1

 private void ShowPanel1_Click(object sender, EventArgs e)
    {
        Panel Panel1Var = new Panel();
        Panel1Var = Panel1;
        Panel2.Hide();
        Panel1.Show();
    }
1

1 Answers

0
votes

You are trying to clear out the textbox when you move back? That can be accomplished by looking at all of the components in the panel, finding the textbox, and clearing it. Like:

foreach (Control p in Panel1.Controls)
  if (p is TextBox)
     p.Clear(); //or use .text like below
     p.Text = "";