开发者

Dialog Window to flash when non parent form is clicked

开发者 https://www.devze.com 2022-12-07 17:50 出处:网络
I have a parent form (let\'s call it formA) which opens other forms (formB and formC) using the Show method. It also opens dialog a dialog (dialog1) using ShowDialog.

I have a parent form (let's call it formA) which opens other forms (formB and formC) using the Show method. It also opens dialog a dialog (dialog1) using ShowDialog.

When dialog1 is open and the user clicks formA, the dialog window flashes. However if the user clicks on formB or formC the dialog does not flash (or come to the foreground).

If the formA and dialog1 are behind some other application and the user clicks on formB (which may be on a different monitor) they may get the impression that the application is froze.

Is there a way to have a blocking dialog (dialog1 in this case) flash regardless of what open form is clicked on.

A very quick way to reproduce this is to create a WinForms app with 2 buttons on it and the following code.

namespace DialogTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            Form1 form2 = new Form1();
            form2.Show();
        }

        private void btnShowDialog_Click(object sender, EventArgs e)
        {
            Form1 form3 = new Form1();
            form3.ShowDialog();
        }
    }
}

I have tried to adjust the parent of the dialog and that s开发者_运维知识库imply changes which form it will flash for, it looks like a hierarchy approach works. For example, if formB shows the dialog and formB's parent is formA then clicking on formA or formB makes the dialog flash. But clicking on formC still does not make the dialog flash

0

精彩评论

暂无评论...
验证码 换一张
取 消