Einzelnen Beitrag anzeigen

Benutzerbild von Puke
Puke

Registriert seit: 7. Nov 2012
123 Beiträge
 
Delphi XE5 Architect
 
#8

AW: Hintergrund in Listview einfärben

  Alt 27. Nov 2012, 07:32
Ich schreibe mal für andere mit gleichem Problem, eine weniger elegante Lösung hier auf:

Wenn man das Problem hat, dass die Hintergrundfarbe nachdem Text aufhört, verlängeret man einfach den Text bis zur Ende der Coloumn mit Leerzeichen,
benutzt aber nicht mehr.

Delphi-Quellcode:
procedure TForm1.PlaylistViewCustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  hallo:TLIstItem;
  weite : Integer;
  längederliste: Integer;
begin
if Fertig=true
then begin

  defaultDraw:=false;


  //Titel
  weite:= playlistview.Columns[0].Width;
  testlabel.Caption:= item.Caption;
  while testlabel.Width<weite+5 do
  begin
    Testlabel.Caption:=testlabel.caption+DupeString(' ', 1);
  end;
  item.Caption:=testlabel.Caption;

  if Anpassen=true
  then begin

    längederliste:= playlistview.Items.Count;

    //Interpret
    weite:= playlistview.Columns[1].Width;
    testlabel.Caption:= item.SubItems[0];
    while testlabel.Width<weite+5 do
    begin
      Testlabel.Caption:= testlabel.caption+DupeString(' ', 1);
    end;
    item.SubItems[0]:=testlabel.Caption;

    //Album
    weite:= playlistview.Columns[2].Width;
    testlabel.Caption:= item.SubItems[1];
    while testlabel.Width<weite+5 do
    begin
      Testlabel.Caption:= testlabel.caption+DupeString(' ', 1);
    end;
    item.SubItems[1]:=testlabel.Caption;

    //Genre
    weite:= playlistview.Columns[3].Width;
    testlabel.Caption:= item.SubItems[2];
    while testlabel.Width<weite+5 do
    begin
      Testlabel.Caption:= testlabel.caption+DupeString(' ', 1);
    end;
    item.SubItems[2]:=testlabel.Caption;

    //Dauer
    weite:= playlistview.Columns[4].Width;
    testlabel.Caption:= item.SubItems[3];
    while testlabel.Width<weite+5 do
    begin
      Testlabel.Caption:= testlabel.caption+DupeString(' ', 1);
    end;
    item.SubItems[3]:=testlabel.Caption;

    //Bewertung
    weite:= playlistview.Columns[5].Width;
    testlabel.Caption:= item.SubItems[4];
    while testlabel.Width<weite+5 do
    begin
      Testlabel.Caption:= testlabel.caption+DupeString(' ', 1);
    end;
    item.SubItems[4]:=testlabel.Caption;

    //Pfad
    weite:= playlistview.Columns[6].Width;
    testlabel.Caption:= item.SubItems[5];
    while testlabel.Width<weite+5 do
    begin
      Testlabel.Caption:= testlabel.caption+DupeString(' ', 1);
    end;
    item.SubItems[5]:=testlabel.Caption;
    durchgänge:= durchgänge+1;

    if durchgänge=längederliste
    then begin
      durchgänge:=0;
      anpassen:= false;
    end;


  end;



    hallo:= PlaylistView.Items[Item.Index];
  if (Item=nil) then Exit;

  with Sender.Canvas.Brush do
    if Odd(Item.Index) then Color:=cl3dlight
                                                                                            else Color:=clWhite;
  with Sender.Canvas.Font do
    if (titelanzeige.Caption= hallo.Caption) and
        (interpretlabel.caption= Hallo.SubItems[0]) and
        (albumlabel.Caption= hallo.SubItems[1]) and
        (genrelabel.Caption= Hallo.SubItems[2]) then Style:=[fsbold]
                                                                                            else Style:=[];

  with Sender.Canvas.Brush do
    if hallo.Caption+Hallo.SubItems[0]+hallo.SubItems[1]+Hallo.SubItems[2]=Playlistindex then Color:= clwebdarkorange;

  //Text widerherstellen
  TextOutOnListview(Playlistview, Item.Index);

end;
Damit ist das Thema glaub ich beendet.
Gruß Puke
  Mit Zitat antworten Zitat