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;