Autor Beitrag
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 11.12.05 16:01 
Hallo Leute !
Wie könnte man das am einfachsten Lösen.
Ich durchsuche ein bestimmtes Verzeichnis und hätte nun gern zb. alle Dateien in der Listbox die, die erweiterung
Exe tragen als rot angezeigt.
Das selbe sollte eigentlich über einen Timer zur Laufzeit geschehen also solang das Verzeichnis durchsucht wird.
Habs schon mit OnDrawItem probiert komm da aber auch nicht so recht weiter.
Mir fehlt da irgendwie der Ansatz.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var
 i:Integer;
 ext:String;
begin
  for i:=0 to Listbox1.Items.Count-1 do
            begin
  ext := ExtractFileExt(listbox1.Items[i]);
  if ext ='.exe' then // ListBox1.Eintrag:=clred ;
  end;
end;
Jailbird
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 127

Windows XP Pro SP2
Delphi 7 Professional
BeitragVerfasst: So 11.12.05 16:32 
Wichtig! Setze ListBox1.Style := lbOwnerDrawFixed oder ListBox1.Style := lbOwnerDrawVariable (im OI oder im Code)!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  if State = [odSelected] then
  begin
    if ExtractFileExt(ListBox1.Items[Index]) = '.exe' then
      ListBox1.Canvas.Font.Color := clRed
    else
      ListBox1.Canvas.Font.Color := clHighlightText;
    ListBox1.Canvas.Brush.Color := clHighlight;
  end else begin
    if ExtractFileExt(ListBox1.Items[Index]) = '.exe' then
      ListBox1.Canvas.Font.Color := clRed
    else
      ListBox1.Canvas.Font.Color := clWindowText;
  end;
  ListBox1.Canvas.Font.Style := [];
  ListBox1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, ListBox1.Items[Index]);
  ListBox1.Canvas.FrameRect(Rect);
end;
Blackheart666 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: So 11.12.05 17:08 
Danke Jailbird das war genau das was Ich brauchte, sind noch einige Begriffe drin wie odSelected mit denen Ich nicht soviel anfangen kann aber damit werde Ich mich dann gleich näher befassen.
Danke nochmal, hier wird man geholfen.
Jailbird
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 127

Windows XP Pro SP2
Delphi 7 Professional
BeitragVerfasst: So 11.12.05 17:59 
odSelected ist ein Element von TOwnerDrawState. Es markiert, dass das zu zeichnende Element gerade ausgewählt ist. Das od vorne an odSelected kommt von OwnerDraw ;)