using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace danli
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Show(new Form2());
}
private bool IsExist(string formType)
{
bool flag = false;
foreach (Form item in Application.OpenForms)
{
if (formType == item.GetType().ToString())
flag = true;
}
return flag;
}
private void Show(Form form)
{
if (IsExist(form.GetType().ToString()))
{
foreach (Form item in Application.OpenForms)
{
if (item.GetType().ToString() == form.GetType().ToString())
{
form.Dispose();
item.Show();
item.Activate();
}
}
}
else
{
form.Show();
form.Activate();
}
}
}
}