如果我在打开模式对话框时以编程方式最小化应用程序的表单,则该模式对话框将关闭。
但是,如果我在 MessageBox 打开时以编程方式最小化应用程序的窗体,则 MessageBox 不会关闭(即,当我将应用程序恢复到正常窗口状态时,消息框仍然显示)。
这是我展示差异的示例代码:
public partial class Form1 : Form
{
// ...
private void showMessageBoxBtn_Click(object sender, EventArgs e)
{
timer1.Start();
// This MessageBox does *not* get closed when the WindowState of Form1 is set to minimized in timer1_Tick
MessageBox.Show(this, "MessageBox");
}
private void formShowDialogBtn_Click(object sender, EventArgs e)
{
timer1.Start();
// This form gets closed when the WindowState of Form1 is set to minimized in timer1_Tick
Form2 form2 = new Form2();
form2.ShowDialog();
}
private void timer1_Tick(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
timer1.Stop();
}
}
问题:
有没有办法让表单表现得像 MessageBox?