简体   繁体   中英

How to make C# tab switch between form

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.

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.

  1. Add this code this.IsMdiContainer = true; to main form.

  2. Create new form for every menu or button click.

     Form1 frm1; Form2 frm2; Form3 frm3; 
  3. 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(); } } } 
  4. 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(); } 

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