Delphi 6 form set to position itself with poDesktopCenter ends up on "extended" monitor
Asked Answered
E

1

5

I have a Delphi 6 application that launches a Wizard after the main form appears. The Wizard is a modal form. One of my users has their Windows desktop extended to more than one monitor. In their case the main form appears on the primary monitor and the Wizard appears on the Extended monitor. This creates confusion because they think the app has frozen when they try to click on the main form. Since the Wizard is open and modal, nothing happens except they hear the warning "ding" tone that tells you a form is not able to receive input.

What can I do to make sure the Wizard form appears on the same monitor as the main form, in this case the primary monitor? I have the Wizard form set to poDesktopCenter.

Elsie answered 22/6, 2012 at 4:37 Comment(4)
Delphi 6 is like a million years old, isn't it? You might try "poScreenCenter" (vs. "desktop center"). Otherwise go for user-defined position.Injured
I usually use poMainFormCenter instead.Desireedesiri
The desktop extends over both monitors. You are getting the behaviour you asked for.Discant
poMainFormCenter is the way to go..Protohuman
C
8

Manual theory:

Use poMainFormCenter when you want your form to be centered by the Application.MainForm. The application main form is, in short, the first form you can see when you run your application, and you should consider that this main form can be on a different monitor than the active window from which you create and center a new form.

Or if you want to center your form by its Owner, use the poOwnerFormCenter which is IMHO better for user's experience because when you have more than two windows opened by each other, you can move the window to another monitor and create the new window on the monitor where user currently works on.

Practical usecase:

User ran your application on the 1st monitor. The application created the Form2 from its MainForm. User moved that Form2 on the 2nd monitor and from there pressed the button which created another form, Form3.

If you designed your Form3 to use the poMainFormCenter position, the Form3 will be centered by the MainForm which is at this time on a different monitor, what is IMHO confusing.

enter image description here

If you would use code like this for creating and showing Form3:

procedure TForm2.Button1Click(Sender: TObject);
begin
  // the Owner parameter Self (or Form2 here) in the Form3 constructor along 
  // with the Position set to poOwnerFormCenter will ensure you that the form 
  // will be centered by the current form position, so on the current monitor 
  // where the user works on as well
  Form3 := TForm3.Create(Self);
  try
    Form3.Position := poOwnerFormCenter;
    Form3.ShowModal;
  finally
    Form3.Free;
  end;
end;

You will get Form3 centered by the Form2 but mainly on the same monitor as the Form2 currently lies on, as you currently work on:

enter image description here

Cellulitis answered 22/6, 2012 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.