Einzelnen Beitrag anzeigen

Benutzerbild von roga
roga

Registriert seit: 15. Jun 2008
Ort: Sachsen-Anhalt
109 Beiträge
 
Delphi XE8 Professional
 
#9

Re: Listview vsReport Bitmaps

  Alt 11. Dez 2008, 20:28
Hallo Starworld,

habe Dir noch einen Codeschnipsel aus einer meiner Kombos rausgesucht, vielleicht hilft es Dir weiter. Ist aber ohne nachträglichen Test umgeschrieben wurden, daher auch keine Garantie auf Fehlerfreiheit!

Delphi-Quellcode:
procedure TListView1.DrawItem(Sender: TCustomListView;
  Item: TListItem; Rect: TRect; State: TOwnerDrawState);
var i: integer;
    s: string;
    TR1, TR2, ARect: TRect;
    Bmp: TBitmap;
    Col, TransCol: TColor;
    AOrientation: Cardinal;
begin
  // Hintergrundfarbe festlegen
  if Item.Selected then // ausgewählt
  begin
    if Focused then Col := clGray
    else Col := clSilver;
  end else
    Col := clWhite;
  // Hintergrund füllen
  ListView1.Canvas.Brush.Style := bsSolid;
  ListView1.Canvas.Brush.Color := Col;
  ListView1.Canvas.FillRect(Rect);
  ListView1.Canvas.Brush.Style := bsClear;
  // Schriftfarbe, evt. weitere Textattribute
  ListView1.Canvas.Font.Color := clBlack;
  // Textausgabe
  ARect.Left := Rect.Left + 6;
  ARect.Top := Rect.Top + 1;
  ARect.Bottom := Rect.Bottom;
  for i := 0 to ListView1.Columns.Count -1 do
  begin
    ARect.Right := ARect.Left + ListView1.Column[i].Width - 6;
    if (i = 0) then s := Item.Caption
    else s := Item.SubItems.Strings[i-1];
    // Textausrichtung
    case ListView1.Column[i].Alignment of
      taLeftJustify: AOrientation := DT_LEFT;
      taCenter: AOrientation := DT_CENTER;
      taRightJustify: AOrientation := DT_RIGHT;
    end;
    // Grafik in 3. Spalte zeichnen
    if (i = 2) then
    begin
      Bmp := TBitmap.Create;
      if (s = '1') then Bmp.Assign(bild1) else
      if (s = '2') then Bmp.Assign(bild2) else
      ...
      
      TR1 := Classes.Rect(ARect.Left, ARect.Top + 1,
                         ARect.Left + Bmp.Width,
                         ARect.Top + 1 + Bmp.Height);
      TR2 := Classes.Rect(0, 0, Bmp.Width, Bmp.Height);
      TransCol := Bmp.Canvas.Pixels[0, 0]; // Transparentfarbe
      ListView1.Canvas.BrushCopy(TR1, Bmp, TR2, TransCol);
      Bmp.Free;
    end else // Text zeichnen
      DrawText(ListView1.Canvas.Handle, PChar(s), Length(s), ARect, AOrientation);
    // Nächste Spalte
    ARect.Left := ARect.Left + ListView1.Column[i].Width;
  end;
end;
roga
Ronald
  Mit Zitat antworten Zitat