答案 0 :(得分:2)
您可以使用表单Owner
属性设置子表单的所有者:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Owner = this;
form2.ShowDialog();
}
}
然后在您的辅助表格中关闭它:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.Owner != null)
this.Owner.Close();
}
}
答案 1 :(得分:0)
这是一个WinForm解决方案:
private void bLogout_Click(object sender, EventArgs e)
{
DialogResult result= MessageBox.Show("Are you sure want to logout?", "Confirm", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
this.Hide();
new frmLogin().Show();
}
}