资源简介

在C#的WinForm中,用TabControl整合了多个窗体,实现了窗体的切换。这是通过选项卡进行三个窗体之间切换的Demo,有关此Demo的详细介绍,大家可以参考我的博客:https://blog.csdn.net/weixin_43074474/article/details/100120303

资源截图

代码片段和文件信息

using System;
using System.Reflection;
using System.Windows.Forms;

namespace TabControlDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public int[] s = { 0 0 0 };//用来记录窗体是否打开过
        private void tabControl1_SelectedIndexChanged(object sender EventArgs e)
        {
           
            
                if (s[tabControl1.SelectedIndex] == 0)
                {
                    btnX_Click(sender e);
                }
            
        }

        private void Form1_Load(object sender EventArgs e)
        {
            string formClass = “TabControlDemo.Form2“;
            GenerateForm(formClass tabControl1);
        }
        public void GenerateForm(string form object sender)
        {
            //反射生成窗体
            Form fm = (Form)Assembly.GetExecutingAssembly().CreateInstance(form);
            //设置窗体没有边框,加入到选项卡中
            fm.FormBorderstyle = FormBorderstyle.None;
            fm.TopLevel = false;
            fm.Parent = ((TabControl)sender).SelectedTab;
            fm.ControlBox = false;
            fm.Dock = Dockstyle.Fill;
            fm.Show();
            s[((TabControl)sender).SelectedIndex] = 1;
        }

        private void btnX_Click(object sender EventArgs e)
        {
            string formClass = ((TabControl)sender).SelectedTab.Tag.ToString();

            GenerateForm(formClass sender);

        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     36864  2019-08-28 16:08  TabControlDemo\.vs\TabControlDemo\v15\.suo

     文件          0  2019-08-28 15:30  TabControlDemo\.vs\TabControlDemo\v15\Server\sqlite3\db.lock

     文件       4096  2019-08-28 15:30  TabControlDemo\.vs\TabControlDemo\v15\Server\sqlite3\storage.ide

     文件      32768  2019-08-28 15:30  TabControlDemo\.vs\TabControlDemo\v15\Server\sqlite3\storage.ide-shm

     文件    1994112  2019-08-28 16:08  TabControlDemo\.vs\TabControlDemo\v15\Server\sqlite3\storage.ide-wal

     文件      11776  2019-08-28 16:08  TabControlDemo\bin\Debug\TabControlDemo.exe

     文件      42496  2019-08-28 16:08  TabControlDemo\bin\Debug\TabControlDemo.pdb

     文件       1577  2019-08-28 16:08  TabControlDemo\Form1.cs

     文件       4367  2019-08-28 16:08  TabControlDemo\Form1.Designer.cs

     文件       5817  2019-08-28 16:08  TabControlDemo\Form1.resx

     文件        364  2019-08-28 15:58  TabControlDemo\Form2.cs

     文件       1971  2019-08-28 15:58  TabControlDemo\Form2.Designer.cs

     文件       5817  2019-08-28 15:58  TabControlDemo\Form2.resx

     文件        364  2019-08-28 15:58  TabControlDemo\Form3.cs

     文件       1971  2019-08-28 15:58  TabControlDemo\Form3.Designer.cs

     文件       5817  2019-08-28 15:58  TabControlDemo\Form3.resx

     文件        364  2019-08-28 15:58  TabControlDemo\Form4.cs

     文件       1972  2019-08-28 15:58  TabControlDemo\Form4.Designer.cs

     文件       5817  2019-08-28 15:58  TabControlDemo\Form4.resx

     文件        827  2019-08-28 15:30  TabControlDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6794  2019-08-28 15:36  TabControlDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件         42  2019-08-28 15:33  TabControlDemo\obj\Debug\TabControlDemo.csproj.CoreCompileInputs.cache

     文件        766  2019-08-28 15:58  TabControlDemo\obj\Debug\TabControlDemo.csproj.FileListAbsolute.txt

     文件       1186  2019-08-28 16:08  TabControlDemo\obj\Debug\TabControlDemo.csproj.GenerateResource.cache

     文件      10576  2019-08-28 15:30  TabControlDemo\obj\Debug\TabControlDemo.csprojAssemblyReference.cache

     文件      11776  2019-08-28 16:08  TabControlDemo\obj\Debug\TabControlDemo.exe

     文件        180  2019-08-28 16:08  TabControlDemo\obj\Debug\TabControlDemo.Form1.resources

     文件        180  2019-08-28 15:58  TabControlDemo\obj\Debug\TabControlDemo.Form2.resources

     文件        180  2019-08-28 15:58  TabControlDemo\obj\Debug\TabControlDemo.Form3.resources

     文件        180  2019-08-28 15:58  TabControlDemo\obj\Debug\TabControlDemo.Form4.resources

............此处省略25个文件信息

评论

共有 条评论