父窗体包含两个子窗体

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 WindowsFormsApplication18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void showform(Form f)
        {

            int count = 0;
            foreach (Form ff in this.MdiChildren)
            {
                if (f.Name == ff.Name)
                {
                    ff.Focus();
                    count++;
                }
            }
            if(count==0)
            {
                f.MdiParent = this;
                f.Show();
            }
        
        }

        private void 窗体一ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4 f = new Form4();
            showform(f);
          
        }

        private void 窗体二ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form5 f = new Form5();
            showform(f);
        }
    }
}
原文地址:https://www.cnblogs.com/yuyingming/p/5114450.html