rawhu
rawhu

Reputation: 31

Form opens in a random position in Delphi

I wanted to make that form would open in a random position on a screen. I found the similar question here https://stackoverflow.com/a/51314375/19160533 But i didnt get how to implement this. Im using Delphi 11. Thanks!

Upvotes: 0

Views: 206

Answers (1)

Hossein Mehrandish
Hossein Mehrandish

Reputation: 81

You can set the top and left of the form on FormShow:

procedure TForm1.FormShow(Sender: TObject);
begin
  self.Top := Random(1000);
  left := Random(2000);
end;

for a better result, you can calculate the desktop dimensions and subtract the form width and height.

Upvotes: 2

Related Questions