VS2012 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication4 { public partial class Form1 : Form { Panel panel1 = new Panel(); public Form1() { InitializeComponent(); //添加panel控件 this.Controls.Add(panel1); panel1.Size = new Size(100, 100);//设置控件大小 panel1.Location = new Point(20, 20);//设置控件位置 panel1.BackColor = Color.Blue;//设置控件背景颜色 //在panel控件上添加label控件 Label label1 = new Label(); panel1.Controls.Add(label1); label1.Text = "这是按钮";//设置控件内容 label1.Location = new Point(0, 10); //设置字体类型 FontFamily myFonFamily = new FontFamily("宋体"); Font myFont = new Font(myFonFamily, 14, FontStyle.Bold); label1.Font = myFont; //设置字体颜色 label1.ForeColor = Color.Red; } private void button1_Click(object sender, EventArgs e) { //删除panel控件 this.Controls.Remove(panel1); } } } Caesar卢尚宇 2020年8月18日