tags:

views:

305

answers:

4

I have a windows form that pops up a dialog box if certian conditions are met when the form loads. The problem is the window does not stay on top and I can still click thing on the parent. However, there is a button on the form that when pressed opens the same window, when I do this it works as expected (like a dialog window).

Is there an issue with showing a dialog when a form is first loading?

+1  A: 

Are you calling ShowDialog from the Form class? Because it will only set the parent window if called from another Form. Alternatively you can use the overload that has the IWin32Window parameter to specifically set the owner.

tomlog
A: 

can you explain the issue further as this is my code which do not show the form it self until the dialog has been closed either you set the parent or not

  private void Form1_Load(object sender, EventArgs e)
        {
            //your functionality goes here    
            AboutBox1 box = new AboutBox1();
            box.ShowDialog();
        }
    }

on the other side you can also check with TopMost property

Gripsoft
A: 

The ShowDialog method needs to be called from the form that you want to be it's parent/owner in order for it to be modal to that form. Alternatively I believe you can set the owner of a dialog directly but I have never needed to do that.

PeteT
A: 

DaBomb,

To do what you want, you will have to call your modal dialog from the constructor of your main form, NOT from the Form_Load event.

Something like this:

    public Form1()
    {
        InitializeComponent();
        this.Show();
        Form2 popupForm = new Form2();
        popupForm.ShowDialog();
    }
Robert Harvey