当前位置: 首页 > 工具软件 > 1Panel > 使用案例 >

C# panel1 控件显示多窗体

施振海
2023-12-01
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsCS2
{
    public partial class Form1 : Form
    {
        
        

        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
             this.IsMdiContainer = true;//设置父窗体是容器
 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormCS1 form1 = new FormCS1();
            //panel1.Controls.Remove(form1);// 移除 指定的控件
            panel1.Controls.Clear();// 移除 panel1内的所有控件
            form1.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮)
            form1.TopLevel = false; //指示子窗体非顶级窗体
            this.panel1.Controls.Add(form1);//将子窗体载入panel
            form1.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FormCS2 form1 = new FormCS2();
            //panel1.Controls.Remove(form1);// 移除 指定的控件
            panel1.Controls.Clear();// 移除 panel1内的所有控件
            form1.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮)
            form1.TopLevel = false; //指示子窗体非顶级窗体
            this.panel1.Controls.Add(form1);//将子窗体载入panel
            form1.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            FormCS3 form1 = new FormCS3();
            //panel1.Controls.Remove(form1);// 移除 指定的控件
            panel1.Controls.Clear();// 移除 panel1内的所有控件
            form1.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮)
            form1.TopLevel = false; //指示子窗体非顶级窗体
            this.panel1.Controls.Add(form1);//将子窗体载入panel
            form1.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            FormCS4 form1 = new FormCS4();
            //panel1.Controls.Remove(form1);// 移除 指定的控件
            panel1.Controls.Clear();// 移除 panel1内的所有控件
            form1.FormBorderStyle = FormBorderStyle.None; //隐藏子窗体边框(去除最小花,最大化,关闭等按钮)
            form1.TopLevel = false; //指示子窗体非顶级窗体
            this.panel1.Controls.Add(form1);//将子窗体载入panel
            form1.Show();
        }
 
    }
}

 类似资料: