Thursday, July 14, 2011

How to set default form font Delphi 2010

Delphi 2010: How to set Default Font for New Forms

Delphi 2010: Great IDE, but a DefaultFont fix needed!

I use Embarcadero Delphi 2010 (formerly Borland Delphi and/or CodeGear Delphi) for developing various Microsoft Windows®-based applications, and I generally love the IDE (Integrated Development Environment) for this RAD (Rapid Application Development) tool and object-oriented-development language and visual-component-library platform. But, once in a while I find some frustrations that just have to be dealt with the old-fashioned way: a registry-hack (or series of them)!

The latest need for a "fix" came when I moved from Delphi 2010 on Windows XP to using Delphi 2010 on Windows 7.  The old Delphi form-designer default form-font I was accustom too while under XP was Tahoma, which was just fine... but, according to Microsoft:
Users interact with text more than with any other element in Microsoft® Windows®. Segoe UI (pronounced "SEE-go") is the Windows system font. The standard font size has been increased to 9 point.
So, I get Delphi 2010 installed on Windows 7 x64 (64-bit environment) and go about a quick test of creating a new VCL Forms Application — and, for some reason I just rather expected the Default Font for Delphi 2010 to be Segoe UI 9-point... well, that is just not the case.  So, how could I make Segoe UI the default font for Delphi?  It should have been a simple single-entry into the registry (like it used to be in earlier Delphi versions), but no, that no longer works. Instead, the following sequence of registry changes must be implemented...

Registry Edits to Change Delphi 2010 Default Form Font

We start by navigating to the proper Windows Registry location (using REGEDIT). See the picture (click for larger version if needed)...

I began by adding a new key under HKEY_CURRENT_USER\Software\Codegear\BDS\7.0 called FormDesign (notice: no space in name); this is not to be confused with the existing key called "Form Design".

Then, in the existing "Form Design" key (the one with a space in it), edit the value for "Embedded Designer" and set it to False. NOTE: the default font fix we are implementing here will not work unless you turn the embedded-designer off — apparently this is thanks to a bug in Delphi 2010.


Now, within that NEW FormDesign key (the one without a space!), add a key/value(string type) pair as show in the next image. This key has the name DefaultFont and an associated string value that contains your desired default font-name, font-size, and even style (e.g., you could append the word bold to this) — in this example, I wanted Segoe UI 9-point (to fit with Microsoft's Windows-7 standard font guidelines). Notice how if the font-name you choose to use has a *space* in it, you MUST enclose the font-name in double-quotes as shown or the Delphi UI will not implement your default font. There is no space anywhere else in the line I show (i.e., no space after separating comma, etc.)


In the next image, I have shown a screen print of the Delphi 2010 Object Explorer showing the Font property values for a brand new form. you can see that my newly specified default Font-Name and Font-Size are taking effect in the Delphi 2010 IDE, albeit with the caveat that the form-designer is not currently "embedded" (since we had to turn off the embedded-designer to get this to work. You can toggle the embedded-designer back on (registry value = True) when you want to edit forms in the usual non-free-floating-form-editor layout. And, once you have your new form(s) created/saved, you can certainly set the embedded form designer to its default for good if you want (don't worry -- your new default font values are persisted when you save a form and will not change).


Updating Existing Forms to new Default Form Font

To quickly update any existing forms, and the controls / components contained on them, I simply did this:

  1. Created a new empty form (with my new Segoe UI 9-point, from new defaults)
  2. Opened up an existing form that needed its look updated; select-all; copy...
  3. Back on my new empty form, I pasted all the copied items.  Now, assuming you have a font-inheritance-hierarchy that supports what is going on (i.e., ParentFont property = True), your pasted controls should reflect that new look.
  4. Make adjustments for new visual size-differences, etc. in my layout.
  5. Close the old (original) form; name the new form to what the old was and save the new unit with the name of the old.  (note: I have everything under version-control; I suggest having this or some other means for rolling-back if you experience issues).
Enjoy!




No comments: