问题
I want to know if it possible to use tabs (like Google Chrome or many others program) in VS Express 2010 to swap between forms without closing any window.
I know there is the tab control item in the tool box but as far as I know you need to create the tab content in the same form. I'm looking for a way to swap between form like if I put Buttons in the the top of each form (workers, customers, ext) that open the form I clicked and close the one I'm in but not change the main window.
回答1:
You can use MDI parent method. If I understand rightly, this link will help you.
OR
You want it to be in the same window.
Add this code
this.IsMdiContainer = true;
to main form.Create new form for every menu or button click.
Form1 frm1; Form2 frm2; Form3 frm3;
Create this function and call every button click for make to hide all form
private void HideForms() { int frmCount = this.MdiChildren.Count<Form>(); if (frmCount > 0) { for (int i = 0; i < frmCount; i++) { this.MdiChildren[i].Hide(); } } }
After that button1, button2,... click event
private void button1_clicked(...) { HideForms(); if ((frm1 == null) || (frm1.IsDisposed)) frm1 = new Form1(); frm1.MdiParent = this; frm1.Dock = DockStyle.Fill; frm1.Show(); frm1.BringToFront(); }
来源:https://stackoverflow.com/questions/34266329/how-to-make-c-sharp-tab-switch-between-form