Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Center on 800*600 and 640*480

Posted on 1999-01-19
5
153 Views
Last Modified: 2010-04-06
How can I center a button on a screen of 640*480, 800*600 and 1024*768 pixels.

Thanks a lot,
Vincent

0
Comment
Question by:Vincentg
5 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 10 total points
ID: 1362443
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
 
LVL 4

Expert Comment

by:erajoj
ID: 1362444
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
 
LVL 17

Expert Comment

by:inthe
ID: 1362445
erajoj
why you say "use this instead" setbounds position is identical to my method on all sized screens/forms???
Regards Barry
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362446
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
 

Author Comment

by:Vincentg
ID: 1362447
I want to thank all for there comments.

Vincent

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question