zoukankan      html  css  js  c++  java
  • winform --MDI窗体

    1、窗口样式---

    2、isMdiContainer---

    3、True------

    (确定该窗口是MDI容器)

      1 using System;
      2 using System.Collections.Generic;
      3 using System.ComponentModel;
      4 using System.Data;
      5 using System.Drawing;
      6 using System.Linq;
      7 using System.Text;
      8 using System.Threading.Tasks;
      9 using System.Windows.Forms;
     10 
     11 namespace _7._01
     12 {
     13     public partial class Form4 : Form
     14     {
     15         public Form4()
     16         {
     17             InitializeComponent();
     18         }
     19 
     20         private void form2ToolStripMenuItem_Click(object sender, EventArgs e)
     21         {
     22             bool a = false;    //定义一个bool类型的a,
     23             Form2 f2 = new Form2();
     24 
     25             foreach (Form f in this.MdiChildren)
     26             {                           //判断是否已经打开了f2
     27                 if (f.Name == f2.Name)  //已经打开
     28                 {
     29                     a = true;  //a变为true
     30 
     31                     f.WindowState = FormWindowState.Maximized;//最大化
     32 
     33                     f.Show();  // 打开新的
     34                     f2.Close();  // 关闭旧的
     35                 }
     36             }
     37             if (a)  //a为true
     38             {
     39                 foreach (Form f in this.MdiChildren)
     40                 {
     41                     if (f.Name != f2.Name) //当前窗口不是f2
     42                     {
     43                         f.Hide();   //隐藏当前窗口    
     44                     }
     45                 }
     46             }
     47             else    //a为false 即为第一次打开
     48             {
     49                 f2.WindowState = FormWindowState.Maximized;//最大化
     50                 f2.MdiParent = this;//当前窗体是f2的父窗体
     51                
     52                 f2.Show();//打开f2
     53             }
     54         }
     55 
     56         private void form3ToolStripMenuItem_Click(object sender, EventArgs e)
     57         {
     58             bool a = false;    //定义一个bool类型的a,
     59             Form3 f3 = new Form3();
     60 
     61             foreach (Form f in this.MdiChildren)
     62             {                           //判断是否已经打开了f3
     63                 if (f.Name == f3.Name)  //已经打开
     64                 {
     65                     a = true;  //a变为true
     66 
     67                     f.WindowState = FormWindowState.Maximized;//最大化
     68 
     69                     f.Show();  // 打开新的
     70 
     71                     f3.Close();  // 关闭旧的
     72                 }
     73             }
     74             if (a)  //a为true
     75             {
     76                 foreach (Form f in this.MdiChildren)
     77                 {
     78                     if (f.Name != f3.Name) //当前窗口不是f3
     79                     {
     80                         f.Hide();   //隐藏当前窗口    
     81                     }
     82                 }
     83             }
     84             else    //a为false 即为第一次打开
     85             {
     86                 f3.WindowState = FormWindowState.Maximized;//最大化
     87                 f3.MdiParent = this;//当前窗体是f3的父窗体
     88            
     89                 f3.Show();//打开f3
     90             }
     91         }
     92     }
     93 }
     94 
     95 
     96 -------↓--(用了panel,但有BUG)-----------
     97 
     98 
     99 using System;
    100 using System.Collections.Generic;
    101 using System.ComponentModel;
    102 using System.Data;
    103 using System.Drawing;
    104 using System.Linq;
    105 using System.Text;
    106 using System.Threading.Tasks;
    107 using System.Windows.Forms;
    108 
    109 namespace _7._01
    110 {
    111     public partial class Form1 : Form
    112     {
    113         public Form1()
    114         {
    115             InitializeComponent();
    116         }
    117 
    118         private void a1111ToolStripMenuItem_Click(object sender, EventArgs e)
    119         {
    120             bool a=false;    //定义一个bool类型的a,
    121             Form2 f2 = new Form2();
    122 
    123             foreach (Form f in panel1.Controls)
    124             {                           //判断是否已经打开了f2
    125                 if (f.Name == f2.Name)  //已经打开
    126                 {
    127                     a = true;  //a变为true
    128                     f.Show();  // 打开新的
    129                     f2.Close();  // 关闭旧的
    130                 }
    131             }
    132             if(a)  //a为true
    133             {
    134                 foreach (Form f in panel1.Controls)
    135                 {
    136                     if (f.Name != f2.Name) //当前窗口不是f2
    137                     {
    138                         f.Hide();   //隐藏当前窗口    
    139                     }
    140                 }
    141             }
    142             else    //a为false 即为第一次打开
    143             {
    144             f2.WindowState = FormWindowState.Maximized;//最大化
    145             f2.MdiParent = this;//当前窗体是f2的父窗体
    146             f2.Parent = panel1;//f2放在 panel1中
    147             f2.Show();//打开f2
    148             }
    149         }
    150 
    151         private void b2222ToolStripMenuItem_Click(object sender, EventArgs e)
    152         {
    153             bool a = false;    //定义一个bool类型的a,
    154             Form3 f3 = new Form3();
    155 
    156             foreach (Form f in panel1.Controls)
    157             {                           //判断是否已经打开了f3
    158                 if (f.Name == f3.Name)  //已经打开
    159                 {
    160                     a = true;  //a变为true
    161                     f.Show();  // 打开新的
    162 
    163                     f3.Close();  // 关闭旧的
    164                 }
    165             }        
    166             if (a)  //a为true
    167             {
    168                 foreach (Form f in panel1.Controls)
    169                 {
    170                     if (f.Name != f3.Name) //当前窗口不是f3
    171                     {
    172                         f.Hide();   //隐藏当前窗口    
    173                     }
    174                 }
    175             }
    176             else    //a为false 即为第一次打开
    177             {
    178                 f3.WindowState = FormWindowState.Maximized;//最大化
    179                 f3.MdiParent = this;//当前窗体是f3的父窗体
    180                 f3.Parent = panel1;//f3放在 panel1中
    181                 f3.Show();//打开f3
    182             }
    183         }
    184     }
    185 }
  • 相关阅读:
    LeetCode Power of Three
    LeetCode Nim Game
    LeetCode,ugly number
    LeetCode Binary Tree Paths
    LeetCode Word Pattern
    LeetCode Bulls and Cows
    LeeCode Odd Even Linked List
    LeetCode twoSum
    549. Binary Tree Longest Consecutive Sequence II
    113. Path Sum II
  • 原文地址:https://www.cnblogs.com/tonyhere/p/5650563.html
Copyright © 2011-2022 走看看