分组类控件有容器(Panel)控件、分组框(GroupBox)控件、选项卡(TabControl)控件等。
容器控件是由System.Windows.Forms.Panel类提供的。该控件相当于一个容器,主要作用就是将其它控件组合在一起放在一个面板上,使这些控件更容易管理。
编写程序,制作一个“下载资源管理器”。
开发步骤如下:
1、首先在Form1窗体中添加三个Button控件,并修改这些控件的Text属性;然后再添加一个Panel控件,并将该控件的Size属性设置为“307,181”。









2、接着再新建三个窗体,分别 为Regular.cs常规窗体、Download.cs下载窗体和Appearance.cs外观窗体,并且为三个窗体添加相应的控件。这里还需要注意,窗体新建完成之后 ,也需要将它们的Size属性设置为“307,181”。
右键,选择重命名。






3、最后在Form1.cs文件中,添加三个Button控件的Click事件。

代码之前

代码之后:

代码如下:
- 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 WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- Regular myRegular=new Regular();
- myRegular.TopLevel = false;
- this.panel1.Controls.Add(myRegular);
- myRegular.FormBorderStyle= FormBorderStyle.None;
- myRegular.BringToFront();
- myRegular.Show();
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- Download myDownload = new Download();
- myDownload.TopLevel = false;
- this.panel1.Controls.Add(myDownload);
- myDownload.FormBorderStyle = FormBorderStyle.None;
- myDownload.BringToFront();
- myDownload.Show();
- }
-
- private void button3_Click(object sender, EventArgs e)
- {
- Appearance myAppearance = new Appearance();
- myAppearance.TopLevel = false;
- this.panel1.Controls.Add(myAppearance);
- myAppearance.FormBorderStyle = FormBorderStyle.None;
- myAppearance.BringToFront();
- myAppearance.Show();
- }
- }
- }
运行结果如下:

点击,无反应, 运行失败。
三个窗口重新设计:



再次运行:



分组框控件是由System.Windows.Forms.GroupBox类提供的,作用是为其他控件提供可识别的分组,可在同一页面实现多个单选RadioButton控件。通常,使用分组框来按功能细分窗体。
选项卡控件是一个选项卡控件,在实际 编程中经常用到,该控件的作用是将相关的组件组合到一系列选项卡页面上。
1、添加和删除TabControl控件中的选项卡
2、以编程方式添加和删除选项卡。