1 (edited by CDB 2020-04-15 04:45:02)

Topic: Can a form be centred on screen without it jumping

I have a form which has constraints as to maximum height and width when the maximise button is clicked.

I have the following code to make sure the form stays centred on the screen when maximised.

procedure Form1_OnResize (Sender: TObject);
begin
  form1.Left := (screen.Width - form1.width) div 2;
  form1.Top := (screen.Height - form1.Height) div 2;

end;

The problem with this is that the form visibly jumps between the top left corner and the final resting place as per the code above.  Does anyone have any ideas to workaround this and make the screen centering more smooth?

My default form settings are:


Position = poMainFormCentre


Width = 952
Height = 461


MaxHeight = 750
MaxWidth = 1500


Min height and width is zero

On a clear disk you can seek forever

Re: Can a form be centred on screen without it jumping

Hello CDB

And if you started by setting the position property of your form on poScreenCenter from the Object Inspector.?
Then you play with the dimensions of your form

JB

Re: Can a form be centred on screen without it jumping

Thanks for the idea Jean, but sadly that makes no difference.


And if you started by setting the position property of your form on poScreenCenter from the Object Inspector.?

On a clear disk you can seek forever

Re: Can a form be centred on screen without it jumping

Hi CDB, Hi Jean,
Can you upload your project?  I was trying to replicate the problem based on the details in your earlier post but couldn't get it to behave as you described.
Derek.

5 (edited by CDB 2020-04-16 01:39:21)

Re: Can a form be centred on screen without it jumping

Hi Derek,


Project uploaded! Note I have made the alteration suggested by Jean in the project.


I might make just a plain form in Delphi or Lazarus and see if I get the same result.


Just as an aside do you know if the graphics.dll which has appeared in my files actually contains the png files I am using on this project?  The total of the size of the individual files are very close to the size of the DLL file.


Thank you for having a look.


PS: I am aware of a foreign key problem in the DB causing duplication when supplier names is used.

Post's attachments

Attachment icon workshop.zip 352.54 kb, 247 downloads since 2020-04-16 

On a clear disk you can seek forever

6 (edited by derek 2020-04-16 12:00:34)

Re: Can a form be centred on screen without it jumping

Hi,
I'd try changing the 'position' property of 'frmmain' to 'podesigned' (your script is already taking care of the form's co-ordinates);  see the attached screenshot.
Derek.

Post's attachments

Attachment icon cdb screenshot.jpg 172.73 kb, 132 downloads since 2020-04-16 

Re: Can a form be centred on screen without it jumping

Thanks for the idea Derek,  but that makes no difference.  It is not a great problem, I can live with it.

I might try it on a different PC and see if it is indeed a quirk of the PC I'm developing it on.

On a clear disk you can seek forever