这是因为打印机和屏幕的单位不同。
GetDriveCaps().

解决方案 »

  1.   

    to: Apollo47(阿波罗) 
    怎么用,能不能给个例子看看?谢了
      

  2.   

    这里有你想要的:
      http://www.csdn.net/expert/topic/201/201720.shtm 
      

  3.   

    试试这个://*******  unit1.dfm    ************
    object Form1: TForm1
      Left = 192
      Top = 168
      Width = 544
      Height = 375
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PrintScale = poNone
      PixelsPerInch = 96
      TextHeight = 13
      object StringGrid1: TStringGrid
        Left = 40
        Top = 112
        Width = 337
        Height = 209
        TabOrder = 0
      end
      object Button1: TButton
        Left = 224
        Top = 48
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 1
        OnClick = Button1Click
      end
    end
    //*******  unit1.pas    ************
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Grids;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses
      Printers;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var
      tb:TBitmap;
      Info: PBitmapInfo;
      InfoSize: DWORD;
      Image: Pointer;
      ImageSize: DWORD;
      Bits: HBITMAP;
      DIBWidth, DIBHeight: Longint;
      PrintWidth, PrintHeight: Longint;
    begin
      Tb := TBitmap.Create;
      try
        Tb.Width := StringGrid1.Width;
        Tb.Height := StringGrid1.Height;
        Tb.Canvas.Brush := StringGrid1.Brush;
        Tb.Canvas.FillRect(Rect(0,0,Tb.Width,Tb.Height));
        Tb.Canvas.Lock;
        try
          StringGrid1.PaintTo(Tb.Canvas.Handle, 0, 0);
        finally
          Tb.Canvas.Unlock;
        end;
      except
        Tb.Free;
        raise;
      end;  Printer.BeginDoc;
      try
        try
          { Paint bitmap to the printer }
          with Printer do
          begin
            Bits := Tb.Handle;
            GetDIBSizes(Bits, InfoSize, ImageSize);
            Info := AllocMem(InfoSize);
            try
              Image := AllocMem(ImageSize);
              try
                GetDIB(Bits, 0, Info^, Image^);
                with Info^.bmiHeader do
                begin
                  DIBWidth := biWidth;
                  DIBHeight := biHeight;
                end;
                PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle,
                        LOGPIXELSX), PixelsPerInch);
                PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle,
                        LOGPIXELSY), PixelsPerInch);            StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0, 0,
                  DIBWidth, DIBHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
              finally
                FreeMem(Image, ImageSize);
              end;
            finally
              FreeMem(Info, InfoSize);
            end;
          end;
        finally
        end;
      finally
        tb.free;
        Printer.EndDoc;
      end;end;end.