Autor Beitrag
Blackheart
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Mi 23.03.05 23:45 
Hallo Leute
Habe folgendes Problem Ich möchte gern den Selektierten Eintrag in der Listbox rot färben
nur leider färbt er mir aber alle Einträge in der Listbox.
Wo liegt der Fehler ?




ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
    Box : TListBox;
    i:Integer;
begin
  i:=Listbox1.ItemIndex;
  if (Control is TListBox) then begin
    Box := TlistBox(Control);
     if Box.selected[i] = true then
      Box.Canvas.Font.Color := clred
    else
      Box.Canvas.Font.Color := clblack;
    Box.Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Box.Items[i]);
  end;
end;
demo88
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

Ubuntu 6.04, Win XP
Delphi 7
BeitragVerfasst: Mi 23.03.05 23:55 
Also entweder ich vertue mich jetzt ganz start oder du machst das zu kompliziert :wink:

1. und 2. :

Zitat:
ausblenden Delphi-Quelltext
1:
2:
  if (Control is TListBox) then begin   
    Box := TlistBox(Control);


Das ist doch 100% eine Listbox, das brauchst du doch nicht zu überprüfen?
Warum baust du "Box" als 2. Listbox da rein. Es reicht doch die eine.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Do 24.03.05 00:05 
user profile iconBlackheart hat folgendes geschrieben:

i:=Listbox1.ItemIndex;
if Box.selected[i] = true then
Box.Canvas.Font.Color := clred
[/delphi]

Das bedeutet: "Falls selektiertes Item selektiert ist, dann rot einfärben". Das ist natürlich immer der Fall ;)
Der Index des zu zeichnenden Items ist Index, den hast du nirgends gebraucht ;)
:arrow: Also entweder if Box.Selected[Index] oder if Box.ItemIndex=Index.
Blackheart Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 164

ME
D3Prof.-D6Standard
BeitragVerfasst: Do 24.03.05 00:18 
Danke delfiphan genau das wars [Index] !!!