Delphi 6 form set to position itself with poDesktopCenter ends up on “extended” monitor

房东的猫 提交于 2019-12-10 14:19:33

问题


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.


回答1:


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.

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:



来源:https://stackoverflow.com/questions/11150252/delphi-6-form-set-to-position-itself-with-podesktopcenter-ends-up-on-extended

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!