I develop a legacy Delphi 6 application, and I would like to increase the font size of one of the forms. All other forms have Microsoft Sans Serif 8pt, but this one is set to Microsoft Sans Serif 7pt. All controls have ParentFont = True, so I could simply set the font size of the form to 8pt. The problem is that the form and its controls won’t resize, and the text of the labels would overlap. Is there a simple way to resize the form after resizing its font, without resizing its controls manually in the form editor?
I develop a legacy Delphi 6 application, and I would like to increase the
Share
At designtime you can effect the change by editing the .dfm file manually. Make sure that the form is saved with the
Scaledproperty set toTrue.Then, close your project in Delphi, or close Delphi altogether. Next open the .dfm file in a text editor and adjust the forms
TextHeightproperty. For example, if you want to scale from 7pt to 8pt, andTextHeightis set to13, then you should change it to11. Then re-load the project and open the form in the designer and your form will be scaled. This won’t be a perfect scaling because you aren’t allowed floating point values forTextHeight. But it may be good enough.At runtime, you can to call
ChangeScale:Note that
ChangeScaleis a protected member. So, depending on where you are calling this, you may need to use the protected member hack.One option then would be to call the form persistence framework at runtime to generate a scaled version of the .dfm file. That would allow you more precise control than playing tricks with
TextHeightFor example, you can attach the following to the
OnShowevent of your form:This will generate a new .dfm file based on the runtime state. You can then compare this with the version of the .dfm file that is in your revision control system. There will be a few changes that you won’t want to accept, but mostly the changes will be the position and size changes that you do want.