Can a form tell if there are any modal windows open?

后端 未结 6 2028
庸人自扰
庸人自扰 2020-12-14 07:08

How, being inside the main form of my WinForm app can I tell if there are any modal windows/dialogs open that belong to the main form?

6条回答
  •  鱼传尺愫
    2020-12-14 07:54

    Timers still run and fire events.
    Example that works...

    public partial class Form1 : Form
    {
        Form2 f2 = new Form2();
        public Form1()
        {
            InitializeComponent();
        }
    
        private void timer1_Tick(object sender, EventArgs e)
        {
            f2.UpdateData(DateTime.Now.ToString());
            if (!f2.Visible) f2.ShowDialog();
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            f2.ShowDialog();
            MessageBox.Show("Done");
        }
    }
    

提交回复
热议问题