惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - lemontree

SQL SERVER学习计划 新的开始 C#.NET禁止一个程序启动多个实例 - lemontree - 博客园 winform里c#验证用户正确后 怎么打开新窗口时关闭登陆窗口 Are You Going To Scarborough Fair中文歌词 安装VS2005 SP1失败 (转载)浅析HTTP协议 (转载)你是合格的程序员吗?—合格程序员应该具备的12种能力 夯实基础,从HTML开始 SQLserver2000〔Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server不存在或访问被拒绝 压缩数据库日志文件 RDLC报表(一) [转载]OWC做电子表格和图表的试验 .net 2.0 Configuration Error 浅谈ASP.NET的内部机制(一) seo专题之开篇有益 引用Microsoft.Office.Interop.Excel出现的问题 OWC生成Excel的效能优化 妇女节各人的不同回复
MDI窗体,子窗体在父窗体中最大化,如果子窗体已经打开则显示,不重复打开窗体
lemontree · 2009-06-09 · via 博客园 - lemontree

在网上找了两个解决办法:最大的不同点是一个用了父窗体的MdiChildren来作为判断依据,而另一个则是用Application.OpenForms,试了一下都可以,哪天再研究下。

第一个,转自:http://www.cnblogs.com/virusswb/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication4
{
    
public partial class frmMain : Form
    
{
        
public frmMain()
        
{
            InitializeComponent();
        }


        
private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)
        
{
            
foreach (Form form in Application.OpenForms)
            
{
                
if (form.Name == "frmLogin")
                
{
                    form.Activate();
                    form.WindowState 
= FormWindowState.Maximized;
                    
return;
                }

            }


            frmLogin login 
= new frmLogin();

            login.MdiParent 
= this;
            login.WindowState 
= FormWindowState.Maximized;
            login.Show();
        }


        
private void 日志ToolStripMenuItem_Click(object sender, EventArgs e)
        
{
            
foreach (Form form in Application.OpenForms)
            
{
                
if (form.Text == "frmLogInfo")
                
{
                    form.Activate();
                    
return;
                }

            }


            frmLogInfo log 
= new frmLogInfo();
            log.MdiParent 
= this;
            log.WindowState 
= FormWindowState.Maximized;
            log.Show();
        }


        
private void frmMain_Load(object sender, EventArgs e)
        
{
            frmLogin login 
= new frmLogin();
            login.WindowState 
= FormWindowState.Maximized;
            login.MdiParent 
= this;
            login.Show();
        }


    }


}

-------------------------------------分割线--------------------------------------------------------------------------------------------

2.MDI窗体:创建MDI父窗体方法

(1)选中Form1窗体,属性窗口中,设置IsMDIContainer为“True”(即该窗体为子窗体的MDI父窗体)

(2)拖一个MenuStrip“菜单”组件到Form1中,将第一个主菜单设置为“文件”,在下拉菜单中增加“打开Form2子窗体”和“关闭”两项。

3.MDI窗体:创建MDI子窗体方法

(1)在项目解决方案管理器上右击项目添加新建项,添加一个Windows窗体,Form2。

(2)双击“打开Form2子窗体”菜单按钮触发事件:

private void 打开Form2子窗体ToolStripMenuItem_Click(object sender, EventArgs e)

       Form2 frm2 = new Form2();
         frm2.MdiParent = this;
         frm2.Show();

     }

4.MDI窗体:确定活动的MDI子窗体(不允许连续单击弹出Form2子窗体)

双击“打开Form2子窗体”菜单按钮触发事件:

private void 打开Form2子窗体ToolStripMenuItem_Click(object sender, EventArgs e)

  foreach (Form childFrm in this.MdiChildren)  //this表示这个窗体(父窗体)
      { if (childFrm.Name == "Form2")
         if (childFrm.WindowState == FormWindowState.Minimized) //如果该子窗体最小化

              childFrm.WindowState = FormWindowState.Normal;  //把它变为正常大小窗口
                   childFrm.Activate(); //把该子窗口设为活动窗口
                   return;
                }
           else
                 childFrm.Activate();  //其他正常大小或最大化的窗口直接将它设置为活动窗口
                   return;
                }
           }
        }

         Form2 frm2 = new Form2();
         frm2.MdiParent = this;
         frm2.Show();

     }

5.MDI窗体:在父窗体中排列MDI子窗体方法

在"打开Form2子窗体"菜单按钮触发事件代码中的最后加入下面一句话:

this.LayoutMdi(MdiLayout.TileHorizontal);  //TileHorizontal表示平铺排列(不设为活动窗口时连续按该菜单后该子窗体平铺排列);此外,MdiLayout的属性还有:TileVertical(垂直平铺)、ArrangeIcons(子图标层叠排列)、Cascade(大窗口层叠排列)