zoukankan      html  css  js  c++  java
  • WinForm MDIParent如何防止重复打开

    DI,全称是多文档界面(Multiple Document Interface),主要应用于基于图形用户界面的系统中。其目的是同时打开和显示多个文档,便于参考和编辑资料。

      下面是一个WinForm MDI小例子。

    复制代码
     1 using System;
    2 using System.Windows.Forms;
    3
    4 namespace WinFormMDI
    5 {
    6 public partial class FrmMain : Form
    7 {
    8 public FrmMain()
    9 {
    10 InitializeComponent();
    11 }
    12
    13 private void Child1ToolStripMenuItem_Click(object sender, EventArgs e)
    14 {
    15 ShowSingleWindow(typeof(FrmChild1));
    16 }
    17
    18 private void Child2ToolStripMenuItem_Click(object sender, EventArgs e)
    19 {
    20 ShowSingleWindow(typeof(FrmChild2));
    21 }
    22
    23 private void ShowSingleWindow(Type type)
    24 {
    25 foreach (Form f in this.MdiChildren)
    26 {
    27 if (f.GetType() == type)
    28 {
    29 f.Activate();
    30 return;
    31 }
    32 }
    33
    34 Form frm = type.Assembly.CreateInstance(type.ToString()) as Form;
    35 frm.MdiParent = this;
    36 frm.WindowState = FormWindowState.Maximized;
    37 frm.Show();
    38 }
    39 }
    40 }
    复制代码

      注:要先设置FrmMain的IsMdiContainer属性为true,这样才能作为mdicontainer。ShowSingleWindow则实现child form实例只有一个。

      效果:

  • 相关阅读:
    973. K Closest Points to Origin
    919. Complete Binary Tree Inserter
    993. Cousins in Binary Tree
    20. Valid Parentheses
    141. Linked List Cycle
    912. Sort an Array
    各种排序方法总结
    509. Fibonacci Number
    374. Guess Number Higher or Lower
    238. Product of Array Except Self java solutions
  • 原文地址:https://www.cnblogs.com/51net/p/10254708.html
Copyright © 2011-2022 走看看