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

后端 未结 6 2031
庸人自扰
庸人自扰 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:41

    Long story short: opening a modal form is blocks execution on the main form as long as the modal window is open, so your main form can never check to see if its opened any modal forms until after the modal form has closed. In other words, your question is based on a misunderstanding of how modal forms work, so its moot altogether.

    For what its worth, it is possible to tell if there are any modal forms open:

    foreach (Form f in Application.OpenForms)
    {
        if (f.Modal)
        {
            // do stuff
        }
    }
    

提交回复
热议问题