Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Problem: ComboBox, DrawItem, Canvas (https://www.delphipraxis.net/69218-problem-combobox-drawitem-canvas.html)

Martin K 11. Mai 2006 21:13


Problem: ComboBox, DrawItem, Canvas
 
Liste der Anhänge anzeigen (Anzahl: 2)
Hi Leute,

ich hab mal wieder ein Problem.

Ich habe mir eine ComboBox auf die Form gelegt und den Style auf 'csOwnerDrawFixed' gesetzt (damit ich per Canvas auf die Items zeichnen kann).

Bei OnDrawItem habe ich folgende Prozedur:
Delphi-Quellcode:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  Rect.Right := Rect.Left + 16;
  ComboBox1.Canvas.TextOut(Rect.Right+2, Rect.Top+2, IntToStr(Index));
  if Index mod 2 = 0 then
    ComboBox1.Canvas.Brush.Color := clBlue
  else
    ComboBox1.Canvas.Brush.Color := clRed;
  ComboBox1.Canvas.FillRect(Rect);
end;
Es soll also, in Abhängigkeit vom Index, eine bestimmte Farbe verwendet werden und dahinter die Nummer des Index stehen.

So sollte es aussehen: Bild1.
Wenn ich mich mit der Mouse über die Items bewege, kommt allerding das bei raus: Bild2.
Das sollte natürlich nicht so sein.

Wer weiß Rat? :gruebel:

jim_raynor 11. Mai 2006 21:26

Re: Problem: ComboBox, DrawItem, Canvas
 
Du solltest am Anfang ein ComboBox1.Canvas.FillRect machen mit dem original Rect.

Delphi-Quellcode:
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  ComboBox1.Canvas.FillRect(Rect);
  Rect.Right := Rect.Left + 16;
  ComboBox1.Canvas.TextOut(Rect.Right+2, Rect.Top+2, IntToStr(Index));
  if Index mod 2 = 0 then
    ComboBox1.Canvas.Brush.Color := clBlue
  else
    ComboBox1.Canvas.Brush.Color := clRed;
  ComboBox1.Canvas.FillRect(Rect);
end;
damit das ganze Item gesäubert wird ;)

Martin K 12. Mai 2006 00:05

Re: Problem: ComboBox, DrawItem, Canvas
 
Danke :thumb:
Das war's!

Warum bin ich da eigentlich nicht selber drauf gekommen? :gruebel:


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:11 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz