为什么我用stringgrid的paintto方法打印出来的控件只有在左上角的一小块

baxp 2001-07-20 12:28:32
为什么我用stringgrid的paintto方法打印出来的控件只有在左上角的一小块
控件缩小了好多倍,而且canvas的大小也缩小了好多,大概只有2*3厘米
...全文
168 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
guig 2001-07-21
  • 打赏
  • 举报
回复
试试这个:

//******* 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;

interface

uses
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;

implementation

uses
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.
baxp 2001-07-20
  • 打赏
  • 举报
回复
to: Apollo47(阿波罗) 
怎么用,能不能给个例子看看?谢了
Apollo47 2001-07-20
  • 打赏
  • 举报
回复
这是因为打印机和屏幕的单位不同。
GetDriveCaps().


baxp 2001-07-20
  • 打赏
  • 举报
回复
kkkk
Apollo47 2001-07-20
  • 打赏
  • 举报
回复
这里有你想要的:
http://www.csdn.net/expert/topic/201/201720.shtm

baxp 2001-07-20
  • 打赏
  • 举报
回复
help me

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧