You can also override that using the OnMeasureItem event like in this sample of a Font Combo by Peter Below
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
const
UM_MEASUREFONTS = WM_USER;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ComboBox1MeasureItem(Control: TWinControl; Index:
Integer;
var Height: Integer);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
Procedure UMMeasureFonts( Var msg: TMessage ); message
UM_MEASUREFONTS;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
combobox1.Items := Screen.Fonts;
combobox1.itemindex := 0;
// Measure items after form has been shown
PostMessage( handle, UM_MEASUREFONTS, 0, 0 );
end;
procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index:
Integer;
var Height: Integer);
begin
// Is called too early to be of use, trying to use the controls
canvas
// to measure items fails since the control is not visible yet.
// Return design-time size + some extra spacing.
Height := (Control As TCombobox).ItemHeight+4;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index:
Integer;
Rect: TRect; State: TOwnerDrawState);
var
cb: TCombobox;
begin
cb:= Control As TCombobox;
cb.Canvas.FillRect( rect );
If (index >= 0) and (index < cb.Items.Count) Then Begin
If odComboBoxEdit In State Then Begin
// Draw the edit portion of the control, use the controls
// design-time font for this since the edit control is
// fixed height and drawing a bunch of symbols if the selected
// font is Symbol etc. is not very informative for the user.
cb.Canvas.Font := cb.Font;
If odSelected In State Then
cb.Canvas.Font.Color := clHighlightText;
End
Else Begin
cb.Canvas.Font.Name := cb.Items[index];
cb.Canvas.Font.Size := 10;
End;
cb.Canvas.TextRect( Rect, rect.left+2, rect.top+2, cb.Items[index]
);
End;
end;
procedure TForm1.UMMeasureFonts(var msg: TMessage);
var
i: Integer;
begin
// use form canvas for measurements
canvas.font.size := 10;
For i := 0 To combobox1.items.count - 1 Do Begin
canvas.font.name := combobox1.items[i];
combobox1.perform( CB_SETITEMHEIGHT,
i,
canvas.TextHeight(combobox1.items[i]));
End; { For }
end;
end.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97:





by: carrzkissPosted on 2009-04-02 at 18:17:57ID: 24055979
I do not have Delphi installed right now due to a recent reinstall of the system.
========== ========== = ========== ========== =
But this is what I found on the subject.
==========================
The control changes its size when the font size changes.
If you want to change the height without changing the font size,
you need to design your own combobox and override the way the height is set.
==========================
hth
Carrzkiss