1
votes

All the modal forms are displayed at Left Top of the screen while the setting are as Follows

  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Position = poOwnerFormCenter

Earlier it used to be display as per setting but recently i made some changes which causes the problem

Let me explain further so you can suggest appropriate solution.

My application has almost more than 50 forms and i open them as CustomerForm.Show/ShowModal. All forms are inherited from one root form which has following code to display icon on task bar

procedure TBaseForm.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.ExStyle := Params.ExStyle or WS_Ex_AppWindow;
  Params.WndParent := GetDesktopwindow;
end;

There was one problem that whenever a file open or file save dialog was opened from any form(whether it is modal form or not) , Main form was coming at Top, to fix this i made a Dummy Main Form and put Application.ShowMainForm := false; in project file and this worked fine but this started all modal form appearing at Left Top Corner of the screen.

Can you please suggests on this?

2
Params.WndParent := GetDesktopwindow looks wrong to me.David Heffernan
How do you create your dummy main form?Ondrej Kelle
@TOndrej using Application.CreateForm(TfrmDummy, frmDummy); in dpr fileGirish
That's not enough information to reproduce your problem, sorry.Ondrej Kelle

2 Answers

0
votes

As you are using the same ancestor for all your windows, you can add your own public function ShowModal with a parameter Parent: TYourForm.

In this method, you get the position of the Parent, calculate the center, and you move your modal window to its center. After, you call the real ShowModal in your own...

0
votes

Add this to the create of your main form:

SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or
  WS_EX_TOPMOST);