How to make C# tab switch between form

99封情书 提交于 2020-01-16 06:56:08

问题


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.

  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();
    }
    


来源:https://stackoverflow.com/questions/34266329/how-to-make-c-sharp-tab-switch-between-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!