How do I find the size of a form programmatically ?

Posted on 2014-11-18
Last Modified: 2014-11-19

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.
Question by:ChLa
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

Expert Comment

ID: 40450735

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!
LVL 27

Accepted Solution

Sinisa Vuk earned 500 total points
ID: 40450847
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 ....

Author Comment

ID: 40451801
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 ?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 27

Expert Comment

by:Sinisa Vuk
ID: 40451946
Components like Form, Panel, Frame, ... have OnResize event and you can use it for what you need.
LVL 19

Expert Comment

ID: 40452325
Alternatively you can set align to alCustom, and use the OnAlignPosition() event do to the aligning yourself.

Author Comment

ID: 40452929
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.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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