|
本文关键字: 多窗口切换 | label | splitContainer | 窗口背景颜色设置 | 字体设置 | 窗口布局 | 按钮事件 | 按钮 |
新建项目: 开发MainForm: MainForm先添加1个splitContainer,然后splitContainer.Panel1添加3个按钮,分别是button1,button2,button3这里设置splitContainer的左侧panel1固定大小,splitContainer1.IsSplitterFixed = false;// IsSpliterFixed属性设为FalsesplitContainer1.FixedPanel = FixedPanel.Panel1;//FixedPannel属性设为Pannel1(要固定的面板的名称) 再右键项目名称添加一个Form1: Form1设计界面添加2个label控件,分别命名为lbTitle,lbContent;控件设置为文本居中,大小固定;在Form1的构造函数修改为传入3个参数,分别为Title,Conten和背景色colorForm1的完整代码: 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 多窗口切换的实现{ public partial classForm1 : Form { public Form1(string title,string content ,Color color) { InitializeComponent( ); lbTitle.Text = title; lbContent.Text = content; this.BackColor = color; lbTitle.Font=new Font("仿宋", 20, FontStyle.Regular); //第一个是字体,第二个大小,第三个是样式 lbContent.Font = new Font("仿宋", 20, FontStyle.Regular); //第一个是字体,第二个大小,第三个是样式 } }}MainForm的完整代码: <code> 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 多窗口切换的实现{public partial classMainForm : Form {//在主窗体初始化3个Form1窗体public Form f1;public Form f2;public Form f3;publicMainForm( ){InitializeComponent( ); splitContainer1.IsSplitterFixed = false;// IsSpliterFixed属性设为False splitContainer1.FixedPanel = FixedPanel.Panel1;//FixedPannel属性设为Pannel1(要固定的面板的名称) }privatevoidMainForm_Load( object sender, EventArgs e ){ string title = "窗口一"; string content = "北国风光,千里冰封。"; Color color = Color.FromArgb(255, 192, 255); //此方法设置的颜色,其透明度属性alpha=255,完全不透明。 f1 = newForm1(title, content,color); f1.Dock = System.Windows.Forms.DockStyle.Fill; f1.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f1.TopLevel = false; title = "窗口二"; content = "成吉思汗,只识弯弓射大雕。"; color = Color.FromArgb(205, 255, 205); //此方法设置的颜色,其透明度属性alpha=255,完全不透明。 f2 = newForm1(title, content,color); f2.Dock = System.Windows.Forms.DockStyle.Fill; f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f2.TopLevel = false; title = "窗口三"; content = "俱往矣,数风流人物还看今朝。"; color = Color.FromArgb(155, 152, 255); //此方法设置的颜色,其透明度属性alpha=255,完全不透明。 f3 = newForm1(title, content,color); f3.Dock = System.Windows.Forms.DockStyle.Fill; f3.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f3.TopLevel = false;//————————————————// 版权声明:本文为博主原创文章,遵循 CC 4.0 BY - SA 版权协议,转载请附上原文出处链接和本声明。//原文链接:https://blog.csdn.net/qq_27474555/article/details/127688352 }privatevoidbutton1_Click( object sender, EventArgs e ){ f1.Show( ); splitContainer1.Panel2.Controls.Clear( ); splitContainer1.Panel2.Controls.Add(f1); }privatevoidbutton2_Click( object sender, EventArgs e ){ f2.Show( ); splitContainer1.Panel2.Controls.Clear( ); splitContainer1.Panel2.Controls.Add(f2); }privatevoidbutton3_Click( object sender, EventArgs e ){ f3.Show( ); splitContainer1.Panel2.Controls.Clear( ); splitContainer1.Panel2.Controls.Add(f3); } }}form1在MainForm初始化时便实例化3个窗口,为后续使用; 整个解决方案的结构: 最终实现的效果: 我的博客地址:https://www.cnblogs.com/StephenYoung 本文参考资料:https://blog.csdn.net/qq_27474555/article/details/127688352https://blog.csdn.net/xieyunc/article/details/89193393https://blog.csdn.net/wojiuguowei/article/details/110927004 </code> 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |