问题描述
标签控件动态生成和三个窗体切换实例。
设计界面
源代码
窗体1
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 _333 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Label lblnew = new Label(); lblnew.Text = "欢迎光临,大家好~这是窗体1"; lblnew.Font = new Font("宋体", 20); lblnew.AutoSize = true; lblnew.BackColor = Color.Brown; lblnew.Location = new Point(100, 30); this.Controls.Add(lblnew); } private void Form1_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { Form2 frmForm2 = new Form2(); this.Hide(); frmForm2.Show(); frmForm2.label1.Text = "这是窗体2"; frmForm2.label1.Font = new Font("宋体", 18); } private void button3_Click(object sender, EventArgs e) { Application.Exit(); } } }
窗体1
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 _333 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { Form1 frmForm1 = new Form1(); this.Hide(); frmForm1.Show(); } } }