1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Printig a Form

Discussion in 'Delphi Programming' started by AdminDF, Jan 6, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    {
    The following code prints all visible TLabel, TEdit, TMemo, TDBText, TDBEdit and
    TDBMemo components on the form with proper place, size and font. Set the Form
    Scrollbar.Range to 768 Horz and 1008 Vert for a 8 X 10.5 page at 96formPPI.
    }


    Code:
    uses Printers;
    
    
    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var
     C : array[0..255] of char;
     CLen, ScaleX, ScaleY, I : integer;
     Format : Word; DC : HDC;
     MComp : TMemo; R: TRect;
    begin
     Printer.BeginDoc;
     DC := Printer.Canvas.Handle;
     ScaleX := GetDeviceCaps(DC, LOGPIXELSX) div PixelsPerInch;
     ScaleY := GetDeviceCaps(DC, LOGPIXELSY) div PixelsPerInch;
     for I := 0 to ComponentCount-1 do
      if (Components is TCustomLabel) or (Components is TCustomEdit) then
       begin
         MComp := TMemo(Components);
         if (MComp.visible) then
          begin
           Printer.Canvas.Font := MComp.Font;
           DC := Printer.Canvas.Handle; {so DrawText knows about font}
           R := MComp.BoundsRect;
           R.Top := (R.Top + VertScrollBar.Position) * ScaleY;
           R.Left := (R.Left + HorzScrollBar.Position) * ScaleX;
           R.Bottom := (R.Bottom + VertScrollBar.Position) * ScaleY;
           R.Right := (R.Right + HorzScrollBar.Position) * ScaleY;
           if (not(Components is TCustomLabel)) and (MComp.BorderStyle = bsSingle)
             then Printer.Canvas.Rectangle(R.Left,R.Top,R.Right,R.Bottom);
           Format := DT_LEFT;
           if (Components is TEdit) or (Components is TCustomMaskEdit) then
            Format := Format or DT_SINGLELINE or DT_VCENTER
           else
           begin
            if MComp.WordWrap then Format := DT_WORDBREAK;
            if MComp.Alignment = taCenter then Format := Format or DT_CENTER;
            if MComp.Alignment = taRightJustify then Format := Format or DT_RIGHT;
            R.Bottom := R.Bottom + Printer.Canvas.Font.Height + 1;
           end;
            CLen := MComp.GetTextBuf(C,255);
            R.Left := R.Left + ScaleX + ScaleX;
            DrawText(DC, C, CLen, R, Format);
           end;
          end;
      Printer.EndDoc;
    end;
     

Share This Page