![]() |
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:
Es soll also, in Abhängigkeit vom Index, eine bestimmte Farbe verwendet werden und dahinter die Nummer des Index stehen.
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; 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: |
Re: Problem: ComboBox, DrawItem, Canvas
Du solltest am Anfang ein ComboBox1.Canvas.FillRect machen mit dem original Rect.
Delphi-Quellcode:
damit das ganze Item gesäubert wird ;)
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; |
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 19:52 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz