![]() |
Listbox Ownerdraw Problem
Hallo liebe Experten,
ich möchte die Einträge in meiner Listbox selber zeichnen, weil abhängig vom Inhalt die Schriftfarbe gesetzt werden soll. Also habe ich das Ereignis entsprechend bestückt. Die Schriftfarbe wird auch entsprechend gesetzt, aber der Markierungsbalken ist in babyblau. Ich hätte ihn gern in $00D7D7D7 (irgendwie grau), aber wenn ich den auskommentierten Code aktiviere, werden alle Zeilen in grau dargestellt wenn ich durch die Liste scrolle (itemindex+1/-1) was mach ich denn falsch?
Delphi-Quellcode:
procedure TForm2.ListBox2DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); var Offset: Integer; { text offset width } nr:integer; begin with (Control as TListBox).Canvas do begin {if index=(Control as TListBox).itemindex then brush.color:=$00D7D7D7 else brush.color:=clWhite;} FillRect(Rect); Offset := 2; font.Style:=[]; font.Size:=16; nr:=StrToInt(copy((Control as TListBox).Items[Index],10,2)); case nr of 69: begin font.color:=clRed; font.Style:=[fsbold]; end; 17,22: font.color:=clGray; 10,13,19,20,31,32,37,53,35,36: font.color:=$000080FF; 11,12,21,33,52: font.color:=clGreen; else font.color:=clBlack; end; TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index]) end end; |
Re: Listbox Ownerdraw Problem
Hi,
beim Zeichnen der Einträge erkennst Du die Zeile mit dem Markierungsbalken nicht am ItemIndex.
Delphi-Quellcode:
sondern am State
if index=(Control as TListBox).itemindex then
brush.color:=$00D7D7D7 else brush.color:=clWhite;
Delphi-Quellcode:
Gruss
if odSelected in State then
brush.color:=$00D7D7D7; |
Re: Listbox Ownerdraw Problem
grandios, läuft.
Vielen Dank! |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:19 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-2025 by Thomas Breitkreuz