Einzelnen Beitrag anzeigen

Popov
(Gast)

n/a Beiträge
 
#9

AW: Item in DrawItem ändern?

  Alt 21. Jun 2014, 12:20
Sollte nicht gehen:
Delphi-Quellcode:
procedure GetFiles(Path: String; List: TStrings);
var
  Search: TSearchRec;
begin
  //Path := IncludeTrailingBackslash(Path);
  if FindFirst(Path + '*.*', faAnyFile, Search) = 0 then
  repeat
    List.Add(Path + Search.Name);
  until FindNext(Search) <> 0;
  FindClose(Search);
end;

procedure TForm1.FormCreate(Sender: TObject);
const
  Path = 'c:\';
begin
  ListBox1.Style := lbOwnerDrawFixed;
  ListBox1.Sorted := True;
  GetFiles(Path, ListBox1.Items);
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
const
  PfadeVerstecken = True; //<<<<
var
  FileName: String;
begin
  with (Control as TListbox) do
  begin
    if PfadeVerstecken then
      FileName := ExtractFileName(Items[Index])
    else
      FileName := Items[Index];

    Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, FileName);

    //Items[Index] := '[Mattze] ' + FileName; //Endlos, wg. Aktualisierung
  end;
end;
ListBox1DrawItem reagiert auf Änderung, dann gibt es eine Änderung im Item, also ruft sich ListBox1DrawItem wieder auf, dann gibt es eine Änderung im Item, usw.

Den Inhalt ändern, der gezeichnet werden soll, ist ja kein Problem (siehe Beispiel).
  Mit Zitat antworten Zitat