How can I set the width and height of a form in Delphi 7? The form contains different types of controls on it. I need to set the main form size to 127×263. It should change programmatically
in a button click.
How can I set the width and height of a form in Delphi 7?
Share
Like so:
Or perhaps you want to set the client area to those dimensions:
Of course, you most commonly set these properties in the Object Inspector at design time and then they are written to your form’s .dfm file.
If you want such a change to occur on a button click add a handler for the button click that looks like this:
In this last excerpt you don’t need to specify the
MainFormobject instance because the event handler is a member of theTMainFormclass and so theSelfis implicit.If you wish to follow Ulrich Gerhardt’s advice (see comment) and use
SetBoundsthen you would write:Finally, if your form has
Scaled = Truethen you need to deal with font scaling. Hard coded pixel dimensions like this will not be appropriate for machines with font scaling set to a different value from your machine.