Mirror

How to hide the font size list in a TFontDialog (Views: 100)


Problem/Question/Abstract:

How can I completely hide the fontsize selection combobox in the font dialog? I have manipulated some properties of the fontdialog but the combobox where you pick the font size is always visible. Furthermore, I want to keep the preview of the font but with a fixed font size.

Answer:

Set the fdLimitSize option in the dialogs Options to true and specifiy the same size for the MinFontsize and Maxfontsize property.

Hide the font size list. This requires a bit of spy work to determine the control IDs in the dialog. Once this has been done you can attach a handler to the fontdialogs Onshow handler:

procedure TForm1.FontDialog1Show(Sender: TObject);
begin
  EnableWindow(GetDlgItem(fontdialog1.handle, 1138), false);
  EnableWindow(GetDlgItem(fontdialog1.handle, 1090), false);
  ShowWindow(GetDlgItem(fontdialog1.handle, 1138), SW_HIDE);
  ShowWindow(GetDlgItem(fontdialog1.handle, 1090), SW_HIDE);
end;

1138 is the handle of the font size combobox (it is a combobox, despite looking like an edit with a list box below it), 1090 the text label above it. Without disabling the controls the accelerator for the size box will close the dialog for some reason.

For the future: the spy works done here was performed this way:

procedure TForm1.Button1Click(Sender: TObject);
begin
  fontdialog1.execute;
end;

function EnumProc(wnd: HWND; lines: TStrings): BOOL; stdcall;
var
  buf, caption: array[0..255] of char;
begin
  result := True;
  GetClassname(wnd, buf, 256);
  GetWindowText(wnd, caption, 256);
  lines.add(format('ID: %d, class: %s, caption: %s', [GetDlgCtrlID(wnd), buf,
    caption]));
end;

procedure TForm1.FontDialog1Show(Sender: TObject);
begin
  memo1.clear;
  EnumChildWindows(fontdialog1.handle, @EnumProc, integer(memo1.lines));
end;

{Output in memo:

ID: 1088, class: Static, caption: Schrift&art:
ID: 1136, class: ComboBox, caption: MS Sans Serif
ID: 1000, class: ComboLBox, caption:
ID: 1001, class: Edit, caption: MS Sans Serif
ID: 1089, class: Static, caption: &Schriftschnitt:
ID: 1137, class: ComboBox, caption: Standard
ID: 1000, class: ComboLBox, caption:
ID: 1001, class: Edit, caption: Standard
ID: 1090, class: Static, caption: &Grad:
ID: 1138, class: ComboBox, caption: 8
ID: 1000, class: ComboLBox, caption:
ID: 1001, class: Edit, caption: 8
ID: 1, class: Button, caption: OK
ID: 2, class: Button, caption: Abbrechen
ID: 1026, class: Button, caption: &bernehmen
ID: 1038, class: Button, caption: &Hilfe
ID: 1072, class: Button, caption: Darstellung
ID: 1040, class: Button, caption: &Durchgestrichen
ID: 1041, class: Button, caption: &Unterstrichen
ID: 1091, class: Static, caption: &Farbe:
ID: 1139, class: ComboBox, caption: Schwarz
ID: 1073, class: Button, caption: Muster
ID: 1092, class: Static, caption: AaBbYyZz
ID: 1093, class: Static, caption:
ID: 1094, class: Static, caption: S&chrift:
ID: 1140, class: ComboBox, caption: Western
}

<< Back to main page