Jump to content
Ian Branch

Proportional scaling of fonts and components when a forms size is changed?

Recommended Posts

Hi Guys,

Back in the D2007 days there was a component called ElasitForm which when put on a form automatically scaled the fonts and components as the form was enlarged or shrunk, proportionally, such that the form looked exactly the same whatever size it was changed to by the User.

ElastiForm isn't available any more and in any case I suspect, possibly wrongly, that Delphi can do that sort of this in its own right now.

Is this correct?  If so how?  Or is there some trickery still needed?

Regards & TIA,

Ian

Share this post


Link to post

I think the component you are talking about is called ElasticForm, not ElasitForm.

If you used it before and registered it, you should have received the source code, so if need arises you could try to compile it for newer Delphi versions.

The company (or at least the website) indeed seems to no longer exist.

 

As for your question: I am not aware of such an automatism. There are several components that allow for flexible layouts and also DPI awareness has been improved, but I don't think the functionality of ElasticForm can be achieved easily with built in functionality.

Share this post


Link to post

Hi Thomas,

Yes it was/is ElasticForm, I was just being lazy.  Yes, I have it and yes I can re-do it.

I was just curious as to what was/wasn't done around the functionality these days.

Does nobody make forms that can be full screened or shrunk proportionally?

 

20 minutes later - OK - I have pulled my ElasticForm source up from the archives, redone it for D10.2.3 and it works.  Should be OK for D10.3 too.

 

Let me take this opportunity to thank you for your work on your Delphi utilities, particularly GExperts.  An essential tool for me and the first thing that gets installed..

Have a great 2019.

 

Regards,

Ian

Share this post


Link to post

Nowadays you can use code like this:

procedure TForm1.Button1Click(Sender: TObject);
begin
  ScaleBy(14, 10);
end;

But make sure, that you do not call this too often, because all sizes of VCL controls are integers. That is why, when you call ScaleBy, some rounding happens, and over time you will get loss of precision.

  • Like 2

Share this post


Link to post

There have been a number of components which attempted to address this issue, but none of them worked very well, in my experience. To be fair, the problem is not in the component design, but in the reality that integer points makes font scaling impractical. If we had font sizes -- and scaling -- in floating point values, then scaling would be straightforward. With integer font sizes, we have proportionally large incremental change at the small sizes, and proportionally small incremental changes at large font sizes.

Edited by Bill Meyer

Share this post


Link to post
    Paramw := (DPI shl 16) + DPI;
    Form.Perform(WM_DPICHANGED, Paramw, @NewRect);

Calculate the new pos and size for the window into NewRect.

 

I've bound this to ctrl-mousewheel like browsers/excel zoom, with limited DPI possibilities (to still fit the form into the display).

Step is 24 DPI.

Works fine.

 

Edited by Attila Kovacs

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×