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
  • 相关阅读:
    外星人(alien)
    6. 第 6 章 函数
    5. 第 5 章 循环
    4. 第 4 章 条件选择
    3. 第 3 章 表达式和交互
    2. 第 2 章 C++简介
    1. 第 1 章 计算机和编程简介
    24. 蛇形填数
    23. 开灯问题
    12. aabb
  • 原文地址:https://www.cnblogs.com/shenchao/p/4686937.html
Copyright © 2011-2022 走看看