Ver Mensaje Individual
  #7  
Antiguo 15-02-2017
Avatar de AgustinOrtu
[AgustinOrtu] AgustinOrtu is offline
Miembro Premium
NULL
 
Registrado: ago 2013
Ubicación: Argentina
Posts: 1.858
Reputación: 15
AgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en brutoAgustinOrtu Es un diamante en bruto
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;
  // cargo el combo con la lista de fuentes del sistema para ver como queda
  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;

// lo que sigue es el codigo de los botones
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.

Última edición por AgustinOrtu fecha: 15-02-2017 a las 23:29:36.
Responder Con Cita