如何使C#选项卡在表单之间切换 [英] How to make C# tab switch between form

查看:144
本文介绍了如何使C#选项卡在表单之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在VS Express 2010中使用选项卡(如Google Chrome或许多其他程序)在不关闭任何窗口的情况下在表单之间切换。



我知道工具箱中有标签控制项目,但据我所知,您需要以相同的格式创建标签内容。我正在寻找一种方式来切换表单,就像我将Button放在每个窗体(工作人员,客户,分机)的顶部,打开我单击的窗体并关闭了我所在的窗体但不更改主窗口。

解决方案

您可以使用MDI父级方法。如果我理解正确,则此链接将对您有所帮助。





您希望它位于同一个窗口中。


  1. 将此代码 this.IsMdiContainer = true; 添加到主表单中。


  2. 为每个菜单或按钮点击创建新表单。

      Form1 frm1; 
    Form2 frm2;
    Form3 frm3;


  3. 创建此函数并调用每个按钮以点击make以隐藏所有表单



    pre prerivate $ HideForms
    {
    int frmCount = this.MdiChildren.Count< Form>();
    if(frmCount> 0)
    {
    for(int i = 0; i< frmCount; i ++)
    {
    this.MdiChildren [i]。隐藏();
    }
    }
    }


  4. ,button2,... click事件

      private void button1_clicked(...)
    {
    HideForms (); $($ fr
    )if((frm1 == null)||(frm1.IsDisposed))
    frm1 = new Form1();
    frm1.MdiParent = this;
    frm1.Dock = DockStyle.Fill;
    frm1.Show();
    frm1.BringToFront();
    }



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

这篇关于如何使C#选项卡在表单之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆