• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#WinFromSplitContainer和UserControl组成简单的类似于web系统的框架页 ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

示例效果:
FrameForm分为上左右三区
上区显示TopUC的顶部Logo及欢迎语
左区显示LeftMenuUC的左侧功能按钮菜单
右区显示点击左侧功能按钮后对应的用户控件窗体内容
(事实上功能按钮应该由传统的WinForm菜单来代替 WinForm程序就应该有自己的传统的样式 而不是和Web类似

不过为了类似于web系统的框架页面
所以尝试了本示例)

示例涉及的窗体及用户控件:
FrameForm  框架窗体 包含两个SplitContainer
           SplitContainer1对窗体上下分隔
           SplitContainer2对SplitContainer1的Panel2进行左右分隔
TopUC      顶部用户控件
LeftMenuUC 左侧菜单用户控件 其中包含两个功能按钮button1 button2
ContentUC1 内容用户控件1 为button1所调用 将显示的框架的右区
ContentUC2 内容用户控件2 为button1所调用 将显示的框架的右区

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(00);
            
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(947640);
            
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(00);
            
this.splitContainer2.Name = "splitContainer2";
            
// 
            
// splitContainer2.Panel2
            
// 
            this.splitContainer2.Panel2.BackColor = System.Drawing.SystemColors.ButtonShadow;
            
this.splitContainer2.Size = new System.Drawing.Size(947533);
            
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(947640);
            
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();
        }
    }

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
手把手教会你如何通过C#创建WindowsService发布时间:2022-07-10
下一篇:
C#字符串的长度问题发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap