Answer the question
In order to leave comments, you need to log in
How to do it in c# windows forms?
Good day. There is a form, like the main button in it, and by clicking the button, another form is called in panel
. This is how I add the form
private void openFormBody(object formhi)
{
if (this.panel2.Controls.Count > 0)
this.panel2.Controls.RemoveAt(0);
Form f = formhi as Form;
f.TopLevel = false;
f.Dock = DockStyle.Fill;
this.panel2.Controls.Add(f);
this.panel2.Tag = f;
f.Show();
}
Answer the question
In order to leave comments, you need to log in
Figured it out myself! You need to transfer another form to the form and then simply the form that you have already transferred already attribute this to .Hide();
Option 1: Use a global form variable
Option 2: Use something like this in the close button
foreach (Control item in panel1.Controls)
{
item.Close()
panel1.Controls.Remove(item);
}
if (this.panel2.Controls.Count > 0)
this.panel2.Controls.RemoveAt(0);
Form f = formhi as Form;
f.TopLevel = false;
f.Dock = DockStyle.Fill;
this.panel2.Controls.Add(f);
this.panel2.Tag = f;
f.Show();
f.Closed += (s, args) => this.Close();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question