How to use multiple forms in one csharp panel on one windows form panel?

I am creating an application for teaching children, when I click on the button on the panel, I want to show different forms in the same place on the panel. Can you help with any cross or training links?

+4
source share
5 answers

This question should be posted on the Stackoverflow website, not here.

But you can use this approach to handle the case.

subForm = new SubFormYouWantToLoad(); subForm.TopLevel = false; subForm.FormBorderStyle = FormBorderStyle.None; ContainerPanel.Controls.Add(subForm , 0, 1); subForm .Visible = true; 

This code can be added when you click on a specific button. Here, each subform is added to the panel as a control. You must remove the subform from the panel control list before adding another subform. To do this, it is better to delete, close and delete the first.

  ContainerPanel.Controls.Remove(activeform); activeform.Close(); activeform.Dispose(); 
+6
source

Use custom controls instead of forms and load them in the panel

Example if you want to show usercontrol1

 panel1.Controls.Clear(); panel1.Visible = true; UserControl1 usr1 = new UserControl1(); usr1.Show(); panel1.Controls.Add(usr1); 

If usercontrol2

 panel1.Controls.Clear(); panel1.Visible = true; UserControl1 usr2 = new UserControl2(); usr2.Show(); panel1.Controls.Add(usr2); 
+3
source

You can create multiple forms as custom controls or a control that inherits from the panel. Then you have a parent form with a panel for storing custom controls. Then you can change the active user control in the container when you need to change the panel.

There is an msdn guide for creating custom controls.

http://msdn.microsoft.com/en-us/library/a6h7e207(v=vs.71).aspx

0
source

I used this code to close the form in the panel, but it didn’t work.

 private void button12_Click(object sender, EventArgs e) { dontShowPANEL(); //ActiveForm.Close(); MainImaginCp kj = new MainImaginCp(); //kj.Visible = false; kj.panel2.Controls.Clear(); panel1.Visible = true; EngABCLearning usr1 = new EngABCLearning(); usr1.Show(); kj.panel2.Controls.Add(usr1); //kj.Focus(); } 

And I used the following code to show the form in the panel.

 private void toolStripMenuItem1_LR_ENG_Click(object sender, EventArgs e) { //kids.Form2 hj = new kids.Form2(); //hj.Show(); EngABCLearning gh = new EngABCLearning(); //gh.Show(); gh.TopLevel = false; gh.FormBorderStyle = FormBorderStyle.None; //Panel2.Controls.Add(subForm, 0, 1); panel2.Controls.Add(gh); gh.Visible = true; } 

This closes my main form and exits the application.

0
source

try this i loaded two forms inside one panel

 private void Form1_Load(object sender, EventArgs e) { Form2 f1 = new Form2(); f1.TopLevel = false; f1.AutoScroll = true; panel1.Controls.Add(f1); f1.Dock = DockStyle.Left; f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f1.Show(); //form2 Form3 f2 = new Form3(); f2.TopLevel = false; f2.AutoScroll = true; panel1.Controls.Add(f2); f2.Dock = DockStyle.Left; f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f2.Show(); } 
0
source

Source: https://habr.com/ru/post/1347212/


All Articles