TListBox::onDrawItem - Problem!
-
Hallo, ich habe ein Problem: Ich habe meiner ListBox (lbCheatList) als Style den Wert OwnerDrawFixed gegeben und versuche damit der Selection meine eigene Farbe zu geben. Hier der Code dazu:
void __fastcall TfMain::lbCheatListDrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { lbCheatList->Canvas->Font->Assign(fMain->Font); lbCheatList->Canvas->Font->Color=0xa000+(Index&1)*0x5000; lbCheatList->Canvas->Brush->Color=(Index&1)*0x5000; lbCheatList->Canvas->Pen->Style=psSolid; lbCheatList->Canvas->Pen->Color=lbCheatList->Canvas->Brush->Color; lbCheatList->Canvas->Rectangle(Rect); if(lbCheatList->Selected[Index]) { lbCheatList->Canvas->Font->Color=(Index&1)*0x5000; lbCheatList->Canvas->Brush->Color=0xa000+(Index&1)*0x2800; } lbCheatList->Canvas->Pen->Color=lbCheatList->Canvas->Brush->Color; lbCheatList->Canvas->Rectangle(Rect); lbCheatList->Canvas->Brush->Style=bsClear; lbCheatList->Canvas->TextOut(Rect.Left,Rect.Top,lbCheatList->Items->Strings[Index]); }
Soweit so gut, nur zeichnet er alle die, die nicht selektiert sind so, als wären sie selektiert, außer am Start. Egal, wo ich hingehe. Alle anderen Items behalten auch diese Farbe bei, als wären sie immernoch selektiert. Was mache ich falsch? Wie bekomme ich das so hin, dass die anderen Items normal gezeichnet werden?
EDIT: Beim Scrollen jedoch färbt er alle anderen wieder normal ein.
- Windoof
-
Soso, inzwischen hab ich das Problem auch schon selbst gelöst bekommen... im onClick-Ereignis der ListBox einfach Repaint() aufrufen
Danke für die große Hilfe.
-
Vielleicht hättest du dir einfach (noch?) mal den entsprechenden FAQ-Eintrag ansehen sollen.
void __fastcall TfMain::lbCheatListDrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { if(State.Contains(odSelected)) lbCheatList->Canvas->Brush->Color = clMaroon; else // optional, wenn Standard-Hintergrund nicht weiss bleiben soll lbCheatList->Canvas->Brush->Color = clLime; lbCheatList->Canvas->FillRect(Rect); lbCheatList->Canvas->TextOut(Rect.Left, Rect.Top, lbCheatList->Items->Strings[Index]); }
Und fertig, nix mit Repaint oder so.
PS.
Gut, dass dir um 16:30 noch der Rect-Parameter aufgefallen ist, das sah doch vorherher arg seltsam aus.
-
So gehts natürlich auch... werd's nachher mal probieren. Danke Jansen. Und ja: der RECT-Parameter war mir nochmal aufgefallen... vorher hatte es beim Scrollen auch nicht funktioniert... naja, danke nochmal.