Jump to content
chkaufmann

New TForm - Defaults

Recommended Posts

When I create a new form (File - New - VCL Form) font and size is always like this:

 

  Font.Height = -11
  Font.Name = 'Tahoma'

but I would like to have it like this:

 

  Font.Height = -12
  Font.Name = 'Segoe UI'

Is there a simple way to achieve this? I remember, that I saw a sample with an IDE expert for this, but is there no way to set this default in the IDE or "per project"?

 

Christian
 

Share this post


Link to post
9 hours ago, chkaufmann said:

When I create a new form (File - New - VCL Form) font and size is always like this:


  Font.Height = -11
  Font.Name = 'Tahoma'

Those are the defaults that are established by the Vcl.Graphics.pas unit (see the InitDefFontData() function) during unit initialization, and then applied to the global DefFontData variable, which is used to initialize every TFont object at runtime.

9 hours ago, chkaufmann said:

but I would like to have it like this:


  Font.Height = -12
  Font.Name = 'Segoe UI'

Is there a simple way to achieve this? I remember, that I saw a sample with an IDE expert for this, but is there no way to set this default in the IDE or "per project"?

Not in the IDE, no.  However, the DefFontData variable is publicly accessible, so you can modify it at runtime before creating any of your TForm objects.

 

  • Like 1

Share this post


Link to post
43 minutes ago, Remy Lebeau said:

Not in the IDE, no.  However, the DefFontData variable is publicly accessible, so you can modify it at runtime before creating any of your TForm objects.

I guess you could modify DefFontData in a design time package

  • Like 1

Share this post


Link to post
On 11/7/2019 at 9:55 AM, chkaufmann said:

  Font.Height = -12
  Font.Name = 'Segoe UI'

Is there a simple way to achieve this?

 

In the project file (the DPR file) I do this before the first form is created:

  if (CheckWin32Version(6, 0)) then
  begin
    // Application.DefaultFont is the font used when TForm.ParentFont=True.
    // It is Tahoma by default but should be Segoe UI on Vista and later (according to MS UI guide lines).
    // See InitDefFontData() in graphics.pas
    Application.DefaultFont.Assign(Screen.MessageFont);
    // DefFontData.Name specifies the default font for everything that doesn't specify a specific font.
    // For now we leave it as is (Tahoma). At some point it should follow the system default like above:
    // DefFontData.Name := Screen.MessageFont.Name;
  end;

And then I just make sure to set all forms ParentFont=True at design time.

  • Like 3
  • Thanks 1

Share this post


Link to post
On 11/9/2019 at 11:00 PM, Anders Melander said:

And then I just make sure to set all forms ParentFont=True at design time.

 

I looked at the problem again and this seems the most reasonable solution for me. The only question that remains, how can I set the IDE font used during designing to "Segoe UI, 9pt" because right now, when I choose "ParentFont = True" then I still get "Tahoma 8pt".

 

Christian

Share this post


Link to post
7 hours ago, chkaufmann said:

The only question that remains, how can I set the IDE font used during designing to "Segoe UI, 9pt" because right now, when I choose "ParentFont = True" then I still get "Tahoma 8pt".

I'm afraid I can't answer that.

Supposedly there used to be a registry key that could do the trick (HKCU\Software\Embarcadero\BDS\19.0\FormDesign\DefaultFont) but that didn't work with the embedded form designer and as far as I can tell it no longer work with the detached designer either.

 

I guess you could create an IDE plugin that modifies the form designer but that's probably more work than it's worth.

Maybe just a design time package that modifies Application.DefaultFont like above will do the trick, but that will affect the whole IDE.

 

FWIW I understand the OCD in you that wants the form to use SegoeUI at design time but it shouldn't really matter. If you have designed it "properly" then the form should be able to display correctly with both SegoeUI and Tahoma. After all you don't know what font the end-user will be using.

Share this post


Link to post

Thanks for your answer.

 

You are right regarding "properly" designed forms. Unfortunately I deal with old applications, that are not perfect and I thought, if I see it with the most common font/size used today, I could just fix the major problems. Mainly fix "Top" and "Height" problem are an issue because all labels and controls are higher.

 

Christian

Share this post


Link to post
Guest

Regarding legacy problems, i had a project with a lot of visual levels and (before high DPI) for each level the "ExplicitHeight/Width" properties messed things up. Utterly annoying to keep track of those.

But that was not my point. What i ended up with was a small exe of my own that i ran before each build that went trough the dfm's and changed that. The notion might be useful.

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

×