Why Can't I Preset Location of Modal Form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In my WinForms application, I have a main form, which may or may not be
visible depending on the user's wishes. This main form initiates a separate
thread that starts a data transfer process.

In this thread I want to show a special dialog box. Because the question
must be answered, I'm using ShowDialog to display it. Just before doing so,
I have some simple code to:
- Center it in the main form, if that form is visible
- Center it in the screen otherwise

Yet to my amazement, this centering code (ie. Left & Top) has absolutely no
effect. Why not?

I even hardcoded in a new location but it had no effect either. Here's the
code in question:

frmInstallPrompt frmInstall = new frmInstallPrompt();
frmInstall.DisplayMobileDeviceInfo();
//frmInstall.CenterForm(parentForm, parentForm.WindowState);
frmInstall.Location = new System.Drawing.Point(1000, 1000);
DialogResult retval = frmInstall.ShowDialog();
 
Have you tried:

frmInstall.StartPosition = FormStartPosition.CenterParent;
frmInstall.ShowDialog();

Regards - Octavio
 
Octavio,

Can I say Muchas Gracias?!

Coming from the VB6 world, I wasn't aware of the "FormStartPosition" property.

In point of fact, the "CenterParent" enum doesn't work because the parent
form is a notification window, not the main form I was referring to. But I
discovered another enum called "Manual". When set to this, it then does take
its location information from the Left & Top properties.

Thank you so much for clueing me in!
 
Back
Top