简体   繁体   中英

How to change controllers visibility from another WinForm C#

I have 2 WinForm in Form1 i have Panel and i load Form2 inside Panel(in Form1)

  • My code for open From2 inside Panel1

    Form2 f = new Form2(); f.TopLevel = false; panel1.Controls.Add(f); f.Show();
  • In Form2 i have button for close the Form and hide the Panel , i can close the Form2 but i can't hide the Panel1

  • I don't know how to change the visibility of Panel1 to False

You can subscribe to the Form.Closed event on Form2. Here you can add code for hiding the panel.

Form2 f = new Form2();
f.TopLevel = false;
f.FormClosed += Form2_FormClosed; //Add this line
panel1.Controls.Add(f);
f.Show();

About the Form.Closed event

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM