c# center modal forms

my form launches 3 modal forms.  i'm trying to center the forms based on the parent form.  The first modal form centers based n the screen - no matter which form i launch first it's always the first one that centers based on screen and not on parent.  I have a workaround which is to first launch a blank form and then hide it, but does anyone know why this would occur?
pderingAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
How are you opening up the dialog?

Something like this should work:
    public partial class Form1 : Form
    {

        private void button1_Click(object sender, EventArgs e)
        {
            frmDialog dialog = new frmDialog();
            dialog.StartPosition = FormStartPosition.CenterParent;
            dialog.ShowDialog(this);
        }
    }

Open in new window

0
 
AndyAinscowFreelance programmer / ConsultantCommented:
You can have a look at the form properties - there should be one for the location of the form.  Select the option Center Parent and that should do what you want.
0
 
pderingAuthor Commented:
Thanks!  I was leaving off the "this".
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
>>Thanks!  I was leaving off the "this".

Odd.  My suggestion works with just
            frmDialog dialog = new frmDialog();
            dialog.ShowDialog();

and I have checked that from idle_mind (with a minor change)
            frmDialog dialog = new frmDialog();
            dialog.StartPosition = FormStartPosition.CenterParent;
            dialog.ShowDialog();   //the 'this' is removed

and that also centers to parent
0
All Courses

From novice to tech pro — start learning today.