Usando las ideas de
roman y
ecfisa
No he cambiado ninguna propiedad en tiempo de diseño, todo lo hago en ejecucion
Código Delphi
[-]
procedure TForm2.FormCreate(Sender: TObject);
begin
ComboBox1.Style := TComboBoxStyle.csOwnerDrawFixed;
ComboBox1.OnDrawItem := ComboBox1DrawItem;
ComboBox1.Font.Size := 14;
ComboBox1.Canvas.Font.Size := 14;
ComboBox1.ItemHeight := ComboBox1.Canvas.TextHeight('|') + 2;
ComboBox1.Items := Screen.Fonts;
ComboBox1.ItemIndex := 0;
end;
procedure TForm2.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
Target: TComboBox absolute Control;
begin
Target.Canvas.FillRect(Rect);
if (Index >= 0) and (Index < Target.Items.Count) then
begin
if ([odComboBoxEdit, odSelected] * State = [odComboBoxEdit, odSelected]) then
Target.Canvas.Font.Color := clHighlightText;
Target.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Target.Items[Index]);
end;
end;
procedure TForm2.btnIncreaseClick(Sender: TObject);
begin
ComboBox1.Font.Size := ComboBox1.Font.Size + 1;
ComboBox1.Canvas.Font.Size := ComboBox1.Canvas.Font.Size + 1;
ComboBox1.Height := ComboBox1.Height - 1;
ComboBox1.ItemHeight := ComboBox1.Canvas.TextHeight('|') + 2;
end;
procedure TForm2.btnReduceClick(Sender: TObject);
begin
ComboBox1.Font.Size := ComboBox1.Font.Size - 1;
ComboBox1.Canvas.Font.Size := ComboBox1.Canvas.Font.Size - 1;
ComboBox1.Height := ComboBox1.Height + 1;
ComboBox1.ItemHeight := ComboBox1.Canvas.TextHeight('|') + 2;
end;
Edito: Probando me estoy dando cuenta de que el evento OnDrawItem
no es estrictamente necesario:
Cita:
If an OnDrawItem event handler is not provided, the combo box fills the Rect parameter with the current brush and writes the text value of the item specified by the Index parameter.
|