在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
示例效果: 示例涉及的窗体及用户控件: FrameForm相关代码:
FrameForm
{ /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.SuspendLayout(); this.splitContainer2.SuspendLayout(); this.SuspendLayout(); // // splitContainer1 // this.splitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer1.IsSplitterFixed = true; this.splitContainer1.Location = new System.Drawing.Point(0, 0); this.splitContainer1.Name = "splitContainer1"; this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; // // splitContainer1.Panel1 // this.splitContainer1.Panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; // // splitContainer1.Panel2 // this.splitContainer1.Panel2.Controls.Add(this.splitContainer2); this.splitContainer1.Size = new System.Drawing.Size(947, 640); this.splitContainer1.SplitterDistance = 103; this.splitContainer1.TabIndex = 0; // // splitContainer2 // this.splitContainer2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer2.Location = new System.Drawing.Point(0, 0); this.splitContainer2.Name = "splitContainer2"; // // splitContainer2.Panel2 // this.splitContainer2.Panel2.BackColor = System.Drawing.SystemColors.ButtonShadow; this.splitContainer2.Size = new System.Drawing.Size(947, 533); this.splitContainer2.SplitterDistance = 193; this.splitContainer2.TabIndex = 0; // // FrameForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(947, 640); this.Controls.Add(this.splitContainer1); this.Name = "FrameForm"; this.Text = "FrameForm"; this.Load += new System.EventHandler(this.FrameForm_Load); this.splitContainer1.Panel2.ResumeLayout(false); this.splitContainer1.ResumeLayout(false); this.splitContainer2.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.SplitContainer splitContainer1; private System.Windows.Forms.SplitContainer splitContainer2; } public partial class FrameForm : Form { public FrameForm() { InitializeComponent(); } private void FrameForm_Load(object sender, EventArgs e) { //加载TopForm TopUC ucTop = new TopUC(); this.splitContainer1.Panel1.Controls.Add(ucTop); ucTop.Show(); //加载LeftMenuForm LeftMenuUC ucLeftMenu = new LeftMenuUC(); this.splitContainer2.Panel1.Controls.Add(ucLeftMenu); ucLeftMenu.Show(); ////加载TopForm //TopForm frmTop = new TopForm(); //frmTop.FormBorderStyle = FormBorderStyle.None; //frmTop.TopLevel = false; //this.splitContainer1.Panel1.Controls.Add(frmTop); //frmTop.Show(); ////加载LeftMenuForm //LeftMenuForm frmLeftMenu = new LeftMenuForm(); //frmLeftMenu.FormBorderStyle = FormBorderStyle.None; //frmLeftMenu.TopLevel = false; //this.splitContainer2.Panel1.Controls.Add(frmLeftMenu); //frmLeftMenu.Show(); } }
LeftMenuUC 相关代码:
LeftMenuUC : UserControl
{ public LeftMenuUC() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ContentUC1 ucContent1 = new ContentUC1(); SplitContainer split = (SplitContainer)Parent.Parent; split.Panel2.Controls.Clear(); split.Panel2.Controls.Add(ucContent1); //split.Panel2.Controls.Add(ucContent1); //split.Panel2.Controls.SetChildIndex(ucContent1, 0); ucContent1.Show(); } private void button2_Click(object sender, EventArgs e) { ContentUC2 ucContent2 = new ContentUC2(); SplitContainer split = (SplitContainer)Parent.Parent; split.Panel2.Controls.Clear(); split.Panel2.Controls.Add(ucContent2); //split.Panel2.Controls.Add(ucContent2); //split.Panel2.Controls.SetChildIndex(ucContent2, 0); ucContent2.Show(); } } |
请发表评论