110,578
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.parentForm = this;
f2.Show();
this.Hide();
}
public Form parentForm;
private void button1_Click(object sender, EventArgs e)
{
parentForm.Show();
this.Dispose();
}
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
parentForm.Dispose();
}
主窗体:
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
this.Text = this.Handle.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
Form1 frm = new Form1(this);
frm.Show();
}
}
Form1:
public partial class Form1 : Form
{
private FrmMain _FrmMain;
public Form1(FrmMain frmMain)
{
InitializeComponent();
_FrmMain =frmMain;
}
private void button1_Click(object sender, EventArgs e)
{
Close();
_FrmMain.Visible=true;
}
}
Form2 f2 = new Form2();
f2.Show();
this.Hide();
Form1 f1 = new Form1();
f1.Show();
this.Hide();
主窗体:
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
this.Text = this.Handle.ToString();
}
private void ShowMainForm()
{
this.Visible = true;
}
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
Form1 frm = new Form1();
frm.OnShowMainForm += ShowMainForm;
frm.Show();
}
}
Form1:
public partial class Form1 : Form
{
public delegate void ShowMainFormHandler();
public event ShowMainFormHandler OnShowMainForm;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Close();
if (OnShowMainForm != null)
{
OnShowMainForm();
}
}
}
Program.cs
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(FrmMain.CreateMainForm());
}
主窗体:
public partial class FrmMain : Form
{
private static FrmMain _Instance;
private FrmMain()
{
InitializeComponent();
}
public static FrmMain CreateMainForm()
{
if (_Instance == null || _Instance.IsDisposed)
{
_Instance = new FrmMain();
}
return _Instance;
}
private void button1_Click(object sender, EventArgs e)
{
this.Visible = false;
Form1 frm = new Form1();
frm.Show();
}
}
Form1:
private void button1_Click(object sender, EventArgs e)
{
Close();
FrmMain frm = FrmMain.CreateMainForm();
frm.Show();
}
主窗体:
this.Visible = false;
Form1 frm = new Form1();
frm.ShowDialog();
this.Visible = true;
Form1:
private void button1_Click(object sender, EventArgs e)
{
Close();
}