Search code examples
windowsdelphicommon-controlscolordialog

Changing font in CHOOSECOLOR dialog


I'm using the Windows common controls CHOOSECOLOR dialog, but on Win 7 it sticks out like a sore thumb as it still uses the 'old' Tahoma font.

ChooseColor Dialog

Is there a fairly easy way of getting it to use Segoe UI or some other font?

If it matters, I'm using Delphi/C++Builder...


Solution

  • I don't think it is a good idea to alter the default font, but sure, it's doable:

    function EnumChildProc(hWnd: HWND; lParam: LPARAM): LongBool; stdcall;
    begin
      SendMessage(hWnd, WM_SETFONT, lParam, Integer(true));
      result := true;
    end;
    
    procedure TForm1.ColorDialogShow(Sender: TObject);
    var
      dlg: TColorDialog;
    begin
      if not (Sender is TColorDialog) then Exit;
      dlg := TColorDialog(Sender);
    
      SendMessage(dlg.Handle, WM_SETFONT, Self.Font.Handle, Integer(true));
    
      EnumChildWindows(dlg.Handle, @EnumChildProc, Self.Font.Handle);
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      with TColorDialog.Create(nil) do
        try
          OnShow := ColorDialogShow;
          Execute(Handle);
        finally
          Free;
        end;
    end;
    

    This will use the Form1.Font font.

    Color Dialog with custom font

    Still, in this case, I might just find it acceptable:

    Color Dialog with default font (Tahoma) Color Dialog with Segoe UI font

    Tahoma (Default) vs. Segoe UI

    But! There are issues involved:

    Color Dialog with default font - no issues

    Color Dialog with custom font causing issues

    The safest thing to do, I think, is not to alter the default (intended) appearance of the dialog. Then, at least, you can blame Microsoft for any scaling issues...