AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Nur ausgewählte Einträge einer Listview drucken
Thema durchsuchen
Ansicht
Themen-Optionen

Nur ausgewählte Einträge einer Listview drucken

Ein Thema von verkouter · begonnen am 30. Sep 2018 · letzter Beitrag vom 7. Okt 2018
 
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Nur ausgewählte Einträge einer Listview drucken

  Alt 3. Okt 2018, 22:18
Delphi-Quellcode:
procedure tform1.PrintListview(oListView: TListView; PrintDialog: TPrintDialog; lvTitel: string);
var
 pWidth, pHeight, i: Integer;
 v, h: Real;
 CurItem, iColumnCount: Integer;
 aCols: array of Integer;
 iTotColsWidth, iInnerWidth, TopMarg, LinesOnPage, CurLine, TekstHeight, CurCol: Integer;
 CurRect: TRect;
 CurStr: string;
 CurLeft, NumPages, TmpPos: Integer;
begin
 if PrintDialog.Execute then
  begin
   iColumnCount := oListView.Columns.Count;
   SetLength(aCols, iColumnCount + 1);
   Printer.Title := 'Mischungsliste';
   Printer.Copies := 1;
   Printer.Orientation := poLandscape;
   Printer.BeginDoc;
   pHeight := Printer.PageHeight;
   pWidth := Printer.PageWidth;
   v := (pHeight + (2 * GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY))) / (29.7 * 0.95);
   h := (pWidth + (2 * GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX))) / 21;
   iTotColsWidth := 0;

   for i := 0 to iColumnCount - 1 do
    iTotColsWidth := iTotColsWidth + oListView.Columns[i].Width;

   aCols[0] := Round(1.5 * h); // left margin ?
   aCols[iColumnCount + 0] := pWidth - Round(1.5 * h); // rigth margin ?
   iInnerWidth := aCols[iColumnCount + 0] - aCols[0]; // space between margins ?

   for i := 0 to iColumnCount - 1 do
    aCols[i + 1] := aCols[i] + Round(oListView.Columns[i].Width / iTotColsWidth * iInnerWidth);

   TopMarg := Round(2.5 * v);

  with Printer.Canvas do
    begin
     Font.Size := 6;
     Font.Style := [];
     Font.Name := 'Times New Roman';
     Font.Color := RGB(0, 0, 0);
     TekstHeight := Printer.Canvas.TextHeight('dummy');
     LinesOnPage := Round((pHeight - (5 * v)) / TekstHeight);
     NumPages := 1;

     while (NumPages * LinesOnPage) < oListView.Items.Count do
      inc(NumPages);

     CurLine := 0;
     for CurItem := 0 to oListView.Items.Count - 1 do
     if oListView.Items[CurItem].Selected then
      begin
       if (CurLine > LinesOnPage) or (CurLine = 0) then
        begin
         if (CurLine > LinesOnPage) then
          Printer.NewPage;

         CurLine := 1;
         if Printer.PageNumber = NumPages then
          begin
           MoveTo(aCols[1], TopMarg);
           for i := 1 to iColumnCount - 1 do
            begin
             LineTo(aCols[i], TopMarg + (TekstHeight * (oListView.Items.Count - CurItem + 2)));
             MoveTo(aCols[i + 1], TopMarg);
            end;
          end
         else
          begin
           for i := 1 to iColumnCount - 1 do
            begin
             MoveTo(aCols[i], TopMarg);
             LineTo(aCols[i], TopMarg + (TekstHeight * (LinesOnPage + 1)));
            end;
          end;

         Font.Style := [fsBold];

         for i := 0 to iColumnCount - 1 do
          begin
           TextRect(Rect(aCols[i] + Round(0.1 * h), TopMarg - Round(0.1 * v), aCols[i + 1] - Round(0.1 * h), TopMarg + TekstHeight - Round(0.1 * v)),
            ((aCols[i + 1] - aCols[i]) div 2) + aCols[i] - (TextWidth(oListView.Columns.Items[i].Caption) div 2), TopMarg - Round(0.1 * v), oListView.Columns.Items[i].Caption);
          end;

         MoveTo(aCols[0] - Round(0.1 * h), TopMarg + TekstHeight - Round(0.05 * v));
         LineTo(aCols[iColumnCount] + Round(0.1 * h), TopMarg + TekstHeight - Round(0.05 * v));
         Font.Size := 8;
         Font.Style := [];
         TmpPos := (TextWidth(DateToStr(Date) + ' Seite: ' + IntToStr(Printer.PageNumber) + ' / ' + IntToStr(NumPages))) div 2;
         TmpPos := pWidth - Round(1.5 * h) - (TmpPos * 2);
         Font.Size := 8;
         Font.Style := [];
         TextOut(TmpPos, Round(0.5 * v), DateToStr(Date) + ' Seite: ' + IntToStr(Printer.PageNumber) + ' / ' + IntToStr(NumPages));
         Font.Size := 18;

         if TmpPos < ((pWidth + TextWidth(lvTitel)) div 2 + Round(0.75 * h)) then
          TextOut((pWidth - TextWidth(lvTitel)) div 2, Round(1 * v), lvTitel)
         else
          TextOut(Round(3 * h), Round(1 * v), lvTitel);

         Font.Size := 7;
         Font.Style := [];
        end;

       CurRect.Top := TopMarg + (CurLine * TekstHeight);
       CurRect.Bottom := TopMarg + ((CurLine + 1) * TekstHeight);

       for CurCol := -1 to iColumnCount - 2 do
        begin
         CurRect.Left := aCols[CurCol + 1] + Round(0.1 * h);
         CurRect.Right := aCols[CurCol + 2] - Round(0.1 * h);

         try
          if CurCol = -1 then
           CurStr := oListView.Items[CurItem].Caption
          else
           CurStr := oListView.Items[CurItem].SubItems[CurCol];
         except
          CurStr := '';
         end;

         CurLeft := CurRect.Left; // align left side

         // write string in TextRect
         TextRect(CurRect, CurLeft, CurRect.Top, CurStr);
        end;
       inc(CurLine);
      end;
    end;

   Printer.EndDoc
  end;
end;
Ich habs nicht getestet aber an passender Stelle die Abfrage eingefügt. Hilft das?
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:12 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz