zoukankan      html  css  js  c++  java
  • C#:将子Form加入父Form中

    实现的功能:已建立了多个子Form界面,在父Form界面左面,点击不同标题的链接文本,父Form界面右面显示不同的子界面内容。

    具体如下:

      1、加入split拆分器控件

      2、在splitControl.panel1中添加不同的链接文本,在splitControl.panel2显示不同界面内容。代码如下:

     public partial class Main : Form
        {
            private Form lastForm = null;
            private frmDepartment department = null;
            private frmRole role = null;
            
            public Main()
            {
                InitializeComponent();
            }
    
            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                if (department == null)
                {
                    department = new frmDepartment();
                }
                AddControls(department);
                lastForm = department;
            }
    
            private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                if (role == null)
                {
                    role = new frmRole();
                }
                AddControls(role);
                lastForm = role;
            }
    
    
            private void AddControls(Form form)
            {
                foreach (Control control in this.splitContainer1.Panel2.Controls)
                {
                    lastForm.Controls.Add(control);
                }
                //this.splitContainer1.Panel2.Controls.Clear();
                foreach (Control control in form.Controls)
                {
                    this.splitContainer1.Panel2.Controls.Add(control);
                }
            }
    View Code
  • 相关阅读:
    第二阶段冲刺01
    客户端-服务器模式
    可用性和可修改性战术分析
    质量属性
    《架构漫谈》阅读笔记
    《软件需求模式》06
    《软件需求模式》05
    《软件需求模式》04
    《软件需求模式》03
    《软件需求模式》02
  • 原文地址:https://www.cnblogs.com/shenchao/p/4686937.html
Copyright © 2011-2022 走看看