两段代码
一、
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 program02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Form2 f2 = new Form2();
bool k=true;
private void button1_Click(object sender, EventArgs e)
{
if (k)
{
f2.Show(this);
k = false;
}
}
private void button2_Click(object sender, EventArgs e)
{
f2.Hide();
k = true;
}
}
}
二、
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 program02
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Form1 f1 =(Form1)this.Owner;
f1.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 f1 =(Form1)this.Owner;
f1.Show();
}
}
}
运行结果: