Resizing a Delphi form after changing the font size in the form editor

I am developing an outdated 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 value is equal to Microsoft Sans Serif 7pt . All controls have ParentFont = True , so I can just set the font size in the form of 8pt . The problem is that the form and its controls will not change, and the text of the labels will overlap. Is there an easy way to resize a form after changing the font size without resizing its controls manually in the form editor?

+4
source share
1 answer

In development mode, you can change this change by manually editing the .dfm file. Make sure the form is saved with the Scaled property set to True .

Then close your project in Delphi or completely close Delphi. Then open the .dfm file in a text editor and set the TextHeight property. For example, if you want to scale from 7pt to 8pt and TextHeight is 13 , you should change it to 11 . Then reload the project and open the form in the designer, and your form will be scaled. This will not be ideal scaling since for TextHeight you are not allowed floating point values. But that may be enough.


At run time, you can call ChangeScale :

 ChangeScale(NewFont.Size, OldFont.Size); 

Please note that ChangeScale is a protected member. Thus, depending on where you call it, you may need to use a secure member hack.

Then one of the options would be to invoke a performance save structure at run time to create a scaled version of the .dfm file. This allows you more control than playing tricks with TextHeight

For example, you can attach the following to the OnShow event of your form:

 procedure TMyForm.FormShow(Sender: TObject); var BinaryStream, TextStream: TStream; begin BinaryStream := TMemoryStream.Create; Try BinaryStream.WriteComponent(Self); BinaryStream.Position := 0; TextStream := TFileStream.Create('MyForm.dfm', fmCreate); Try ObjectBinaryToText(BinaryStream, TextStream); Finally TextStream.Free; End; Finally BinaryStream.Free; End; end; 

This will create a new runtime .dfm file. You can then compare this with the version of the .dfm file that is in your version control system. There will be a few changes that you do not want to accept, but basically the changes will be the changes in location and size that you want.

+4
source

All Articles