How do I find the size of a form programmatically ?


I learned to size a form by using auto size and sizing a main panel on the form. This works well but really I should be able to grab the edges of a window and size it this way, then get the size of the window and resize my components. The first problem I encountered is that I cannot access form size programmatically. The other mystery is, which event should I use.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Manuel Lopez-MichelonePhD candidateCommented:

The form is also an object (like a button, for example). So your problem, I guess is very easy to solve. Put a form with a button and try on the click evento of teh button the next code:

procedure TForm1.Button1Click(Sender: TObject);
  ShowMessage('The size of the form is '+ inttostr(Form1.Width) + 'x'+ inttostr(Form1.Height));

Hope this helps!
Sinisa VukSoftware architectCommented:
Best way is to align components according to form. Put panel and set Align to client, put other components on it. Then you can set another panel on same level to left or right.... Components can be resized using Anchor property ....

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChLaProducerAuthor Commented:
This second answer works really well. Is an event triggered after the form has been rezised that I can use to do a few things ?
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Sinisa VukSoftware architectCommented:
Components like Form, Panel, Frame, ... have OnResize event and you can use it for what you need.
MerijnBSr. Software EngineerCommented:
Alternatively you can set align to alCustom, and use the OnAlignPosition() event do to the aligning yourself.
ChLaProducerAuthor Commented:
The Form OnResize event is working well for me now. At first when I tried it I was confused by the fact that the first event occurs when the form is created. I ignored the first event and now it is all good. Thank everyone for their help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.