首页 > 技术文章 > C#多文档程序中如何只打开一个子窗口

China3S 2016-11-27 09:00 原文

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace test
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		private Form1 fm1;
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void 文件ToolStripMenuItem1Click(object sender, EventArgs e)
		{
			if(fm1==null||fm1.IsDisposed)
			{
				fm1=new Form1();
				fm1.MdiParent=this;
				fm1.Show();
			}else
			{
				fm1.Activate();
				fm1.WindowState=FormWindowState.Normal;
			}
		}
	}
}

 

推荐阅读