Thema: Delphi In Kombobox zeichnen

Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#11

Re: In Kombobox zeichnen

  Alt 14. Dez 2004, 09:09
Die Klasse TWinControl kennt das Property Canvas noch nicht.
Deshalb:
Delphi-Quellcode:
procedure TStyle.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  InflateRect(Rect, -1, -1); // Rechteck schrumpfen
  (Control as TComboBox).Canvas.Pen.color := clRed;
  (control as TComboBox).Canvas.Rectangle(Rect);
end;
Wenn deine Zeichenoperationen umfangreicher sind, lohnt es sich den Canvas in einer Variablen zu halten:
Delphi-Quellcode:
procedure TStyle.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
   canv : TCanvas;
begin
  canv := (Control as TComboBox).Canvas;
  InflateRect(Rect, -1, -1); // Rechteck schrumpfen
  canv.Pen.color := clRed;
  canv.Canvas.Rectangle(Rect);
end;
Andreas
  Mit Zitat antworten Zitat