Center on 800*600 and 640*480

How can I center a button on a screen of 640*480, 800*600 and 1024*768 pixels.

Thanks a lot,
Vincent

VincentgAsked:
Who is Participating?
 
intheConnect With a Mentor Commented:
put the following on  form resize or form create:

procedure TForm1.FormResize(Sender: TObject);
begin
with Button1 do begin
Left:=(Parent.Width - Width) div 2;
Top :=(Parent.Height - Height) div 2;
end;
end;

Regards Barry
0
 
erajojCommented:
Use this instead:
  with Button1 do SetBounds( (Parent.Width - Width) div 2, (Parent.Height - Height) div 2, Width, Height );
  or...
  with Button1 do SetBounds( (Screen.Width - Width) div 2, (Screen.Height - Height) div 2, Width, Height );

/// John
0
 
intheCommented:
erajoj
why you say "use this instead" setbounds position is identical to my method on all sized screens/forms???
Regards Barry
0
 
MadshiCommented:
Vincent, if you've Delphi4, just use the anchor property to bind the component to each border...

Barry, if you set "left" and "top" seperately, the buttons is moved/updated/redrawed/checked/blabla/blabla two times.
If you call SetBounds, the button is only xxx one time.
I'm not sure, but I think, changing e.g. Left ends up in a call like this:
  SetBounds(newLeft,top,width,height);

Regards, Madshi.
0
 
VincentgAuthor Commented:
I want to thank all for there comments.

Vincent

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.