5

I've read that the most centralized way to have font-consistency through a project is to have all controls with the ParentFont property active and set the Application.DefaultFont at runtime.

I would like to apply a different font, say 'Segoe UI', in the whole application at design time.

How can it be changed at design time?

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
  • 1
    Segoe UI is an excellent choice, because that is the one prescribed by the [Microsoft Windows User Interface Guidelines](https://learn.microsoft.com/sv-se/windows/win32/uxguide/vis-fonts). I make sure to set this font on each form I create (and then it is inherited by all controls in that form). But unfortunately, I know of no solution to your question. – Andreas Rejbrand Oct 18 '19 at 08:04
  • Of course, even better would be not to hardcode Segoe UI, but to respect the Windows font setting (which will be Segoe UI in >99% of all cases). – Andreas Rejbrand Oct 18 '19 at 08:59
  • 1
    @AndreasRejbrand what exactly is "the Windows font setting"? Where in Windows can it be configured? – dummzeuch Oct 18 '19 at 10:06
  • @dummzeuch: In Windows 95-Windows 7, there was a dialog box, *Display Properties*, with a tab *Appearance*, in which you could customize all colours and fonts in the Windows environment. It might not be present in Windows 8 and later (don't use those systems much). – Andreas Rejbrand Oct 18 '19 at 10:18
  • @AndreasRejbrand I guess you mean the "Fensterfarbe und -darstellung" ("Window colors and display"?) dialog. That one is indeed no longer available in Windows 8 and later. But even in Windows XP and 7 it did not allow to set a default font for the window's client areas, only for the title, the menu etc. – dummzeuch Oct 18 '19 at 12:05
  • 1
    @dummzeuch: I suspected as much. But I am not sure there is a guarantee that the system font is Segoe UI even in Windows 10. See the "If you do only one thing" part at [MSDN](https://learn.microsoft.com/sv-se/windows/win32/uxguide/vis-fonts). Still, I do hardcode Segoe UI in my applications. – Andreas Rejbrand Oct 18 '19 at 12:15
  • This would require support from the IDE and would probably end up at application settings at project options. Perhaps with OTA... .... ... Perhaps not. D7 ota help mentions icon, title, run properties. Only those which are already available at project options... – Sertac Akyuz Oct 18 '19 at 20:10
  • The easiest way to do this is to have a base form that all of your forms inherit from and then set the font there. – Graymatter Oct 18 '19 at 22:18

1 Answers1

0

You have a number of options, what works best for you may depend on your situation.

If you are using your own forms (not from a package or library) then you can design each to inherit from a parent to give you a starting font as suggested in the comments. However the IDE will allow this to be changed, and if the DFM file for the form records a font in the derived form, it will use that font even if the parent class font is changed.

Another approach would be to write a non-visual component that you can drop onto a form. When that component has it's Owner set (at creation) it can check if it is owned by a Form and set the font on the parent. In the same way it can set any properties you want it to, and it can also find the children of it's owner and set any properties on those controls as well.

Moving on from this you could, at runtime, look at the TScreen class which contains properties called CustomForms and Forms which allow you to access all currently active descendents of TCustomForm and TForm respectively. As you can access this you could change the fonts on all of them at runtime. So if you allow your user to select a font, using the Screen object you can change the font on all forms.

The combination of the two can allow you to easily gain control over display properties.

Be aware that changing the font face can change the size of the text rendered. (As of course will changing the font size and style). This can affect how your controls look and the alignment of them.

Rob Lambden
  • 2,175
  • 6
  • 15