Q&A

  • 컴포넌트 프린트요.
지금 컴포넌트를 프린트 할려구 하는데요..



잘 되지 않네요..



프린트를 하면 자꾸 실제 크기로만 되구, (흠사 학종이에 프린트 한듯..-_-;;)



여러군데 뒤지구, 책 보구, HELP보구 해서 찾아두, text 프린트 하는 것과, image 프린트 하는 것 밖에 없다군요.



혹시. 컴포넌트를 바로 확대해서 프린트 하는 방법은 없나요??



벌서 1주일째 머리를 짜서 고생 중입니다..-_-;;;



지금 StringGrid를 사용해서 데이터를 출력했는데, 가능한 방법이 있으면 알려주세요..



1  COMMENTS
  • Profile
    2001.03.06 07:22
    전에 저두 고민했던 문제인데...

    참조하세요.



    function RightPos(iLen: Integer; sTxt: String): Double;

    const

    iSca: Integer = 5;

    iDiv: Integer = 5; // Side

    iVal: Integer = 1;

    begin

    iVal := Printer.Canvas.TextWidth(sTxt);

    result := (iLen - (iVal / iSca) - 8) + ((iVal / iSca) / iDiv);

    end;



    function CenterPos(iJop, iLen: Integer; sTxt: String): Double;

    const

    iSca: Integer = 5;

    iDiv: Integer = 10; // Center

    iVal: Integer = 1;

    begin

    if iJop = 0 then iVal := Printer.Canvas.TextWidth(sTxt);

    if iJop = 1 then iVal := Printer.Canvas.TextHeight(sTxt);

    result := ((iLen - (iVal / iSca)) / 2) + ((iVal / iSca) / iDiv);

    end;



    procedure TPrintFM.PrintObject(Sender: TObject);

    var

    LabelName: TLabel;

    HeaderName: THeader;

    StringGridName: TStringGrid;

    pPnt: TPoint;

    PDC: HDC;

    dScaleX, dScaleY: Double;

    i, j: Integer;

    Q, R: TRect;

    begin

    pPnt.x := 1082; pPnt.y := 760; // Print Area of A4 Size

    pPnt.x := Trunc((pPnt.x - 1016) / 2); // Panel Width = 1016

    pPnt.y := Trunc((pPnt.y - 740) / 2); // Panel Height = 740



    PDC := Printer.Canvas.Handle;

    dScaleX := GetDeviceCaps(PDC, LOGPIXELSX) / 96;

    dScaleY := GetDeviceCaps(PDC, LOGPIXELSY) / 96;



    if Sender is TLabel then begin

    LabelName := (Sender as TLabel);

    with Printer.Canvas do begin // < Label Print >

    Q := LabelName.BoundsRect;

    Q.Left := Trunc((Q.Left + pPnt.x) * dScaleX);

    Q.Top := Trunc((Q.Top + pPnt.y) * dScaleY);

    Font := LabelName.Font;

    TextOut(Q.Left, Q.Top, LabelName.Caption);

    end;

    end;



    if Sender is THeader then begin

    HeaderName := (Sender as THeader);

    with Printer.Canvas do begin // < Header Print >

    Q := HeaderName.BoundsRect;

    Q.Left := Trunc((Q.Left + pPnt.x) * dScaleX);

    Q.Top := Trunc((Q.Top + pPnt.y) * dScaleY);

    Q.Right := Trunc((Q.Right + pPnt.x) * dScaleX);

    Q.Bottom := Trunc((Q.Bottom + pPnt.y) * dScaleY);

    Pen.Width := HeaderName.Height;

    Rectangle(Q.Left, Q.Top, Q.Right, Q.Bottom);

    Pen.Width := 8;

    MoveTo(Q.Left, Q.Bottom); LineTo(Q.Right, Q.Bottom);

    end;

    end;



    if Sender is TStringGrid then begin

    StringGridName := (Sender as TStringGrid);

    with Printer.Canvas do begin // < StringGrid Print >

    Q := StringGridName.BoundsRect;

    Q.Left := Trunc((1016 - StringGridName.Width) / 2) + pPnt.x;

    Q.Top := Q.Top + pPnt.y;

    Font := StringGridName.Font;

    Pen.Width := StringGridName.GridLineWidth;

    for i := 0 to StringGridName.ColCount - 1 do

    for j := 0 to StringGridName.RowCount - 1 do begin

    R := StringGridName.CellRect(i, j);

    R.Left := Trunc((R.Left + Q.Left) * dScaleX);

    R.Top := Trunc((R.Top + Q.Top) * dScaleY);

    R.Right := Trunc((R.Right + Q.Left + StringGridName.GridLineWidth) * dScaleX);

    R.Bottom := Trunc((R.Bottom + Q.Top + StringGridName.GridLineWidth) * dScaleY);

    if (i < StringGridName.FixedCols) or (j < StringGridName.FixedRows) then Brush.Color := StringGridName.FixedColor

    else begin

    Brush.Style := bsClear;

    SetBKColor(PDC, ColorToRGB(clWhite));

    end;

    Rectangle(R.Left, R.Top, R.Right, R.Bottom);

    R.Left := R.Left + Trunc(8 * dScaleX);

    // R.Left := R.Left + Trunc(RightPos(StringGridName.ColWidths[i], StringGridName.Cells[i, j]) * dScaleX);

    R.Top := R.Top + Trunc(CenterPos(1, StringGridName.DefaultRowHeight, StringGridName.Cells[i, j]) * dScaleY);

    TextOut(R.Left, R.Top, StringGridName.Cells[i, j]);

    end;

    Pen.Width := 8;

    Rectangle(Trunc(Q.Left*dScaleX), Trunc(Q.Top*dScaleY), R.Right, R.Bottom);

    end;

    end;

    end;