モーダルダイアログが開いているときにアプリケーションのフォームをプログラムで最小化すると、そのモーダルダイアログは閉じられます。
ただし、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();
}
}
質問:
フォームをメッセージボックスのように動作させる方法はありますか?