有了解决办法:
预览时,用如下代码:
procedure TFrm_Preview.PaintBox1Paint(Sender: TObject);
var
PageSize : TSize;
begin
SetMapMode(PaintBox1.Canvas.Handle, MM_ISOTROPIC);
PageSize.cx := PaintBox1.Width;
PageSize.cy := PaintBox1.Height;
SetWindowExtEx(PaintBox1.Canvas.Handle, FPageWidth, FPageHeight, @PageSize);
SetViewPortExtEx(PaintBox1.Canvas.Handle, PaintBox1.Width, PaintBox1.Height, @PageSize);
DrawOnePage(PaintBox1.Canvas.Handle, PaintBox1.Canvas,iPageWidth,iPageHeight,iLeftMargin,iTopMargin,iRightMargin,iBottomMargin, nFooterMargin, true,PrePpiX,PrePpiY, sMainDir+'/Temp/'+IntToStr(iPageNumber)+'.tmp', iScale);
{
if iScale=100 then
begin
PaintBox1.Height:= Round(ScrollBox1.Height+0.5)-10;
PaintBox1.Width:= Round(PaintBox1.Height*iPageWidth/iPageHeight*1.0+0.5);
end else
begin
PaintBox1.Height:= Round(OrignDrawHeight*iScale/100+0.5);
PaintBox1.Width:= Round(PaintBox1.Height*iPageWidth/iPageHeight+0.5);
end;
}
//DrawOnePage(PaintBox1.Canvas.Handle, PaintBox1.Canvas,iPageWidth,iPageHeight,iLeftMargin,iTopMargin,iRightMargin,iBottomMargin, nFooterMargin, true,iScale, iScale, sMainDir+'/Temp/'+IntToStr(iPageNumber)+'.tmp', iScale);
end;
打印时,用如下代码:
procedure Printting(OffsetLenght: Integer;
CannotMargin: TRect;
nPageNumber: Integer);
var
PageSize :TSize;
begin
//SetMapMode(Printer.Canvas.Handle, mm_Text);
//Printer.Title:= '房屋安全鉴定报告';
if Printer.Orientation=poPortrait then
if OffsetLenght<= iTopMargin then
begin
SetMapMode(Printer.Handle, MM_ISOTROPIC);
PageSize.cx := Printer.PageWidth;
PageSize.cy := Printer.PageHeight;
SetWindowExtEx(Printer.Handle, Printer.PageWidth, Printer.Pageheight, @PageSize);
SetViewPortExtEx(Printer.Handle, Printer.PageWidth, Printer.Pageheight, @PageSize);
DrawOnePage(Printer.Handle, Printer.Canvas,iPageWidth,iPageHeight,iLeftMargin,iTopMargin-OffsetLenght,iRightMargin,iBottomMargin+OffsetLenght,nFooterMargin+OffsetLength, false,PrinterPpiX,PrinterPpiY, sMainDir+'/Temp/'+IntToStr(nPageNumber)+'.tmp', iScale);
end else
Application.MessageBox('打印机偏移量大于上边距,打印错误!', szProgramTitle, MB_OK+MB_ICONERROR)
else
if OffsetLenght<= iLeftMargin then
begin
SetMapMode(Printer.Handle, MM_ISOTROPIC);
PageSize.cx := Printer.PageWidth;
PageSize.cy := Printer.PageHeight;
SetWindowExtEx(Printer.Handle, Printer.PageWidth, Printer.Pageheight, @PageSize);
SetViewPortExtEx(Printer.Handle, Printer.PageWidth, Printer.Pageheight, @PageSize);
DrawOnePage(Printer.Handle, Printer.Canvas,iPageWidth,iPageHeight,iLeftMargin-OffsetLenght,iTopMargin,iRightMargin+OffsetLenght,iBottomMargin, nFooterMargin, false,PrinterPpiY,PrinterPpiX, sMainDir+'/Temp/'+IntToStr(nPageNumber)+'.tmp', iScale);
end else
Application.MessageBox('打印机偏移量大于左边距,打印错误!', szProgramTitle, MB_OK+MB_ICONERROR);
end;
缩放时,用如下代码:
procedure TFrm_Preview.PaintBox1Click(Sender: TObject);
var
lpPoint : TPoint;
begin
GetCursorPos(lpPoint);
LockWindowUpdate(FRM_Preview.Handle);
//Application.ProcessMessages;
PaintBox1.Visible := false;
ScrollBox1.Visible:=false;
if iScale=100 then
begin
//iScale:=Round(190*iPageHeight/186);
iScale:=160;
//PaintBox1.picture := nil;
SetPreviewSize;
SetPreviewPpi;
PaintBox1.Left:= 0;
PaintBox1.Top:= 0;
Scrollbox1.HorzScrollBar.Range := PaintBox1.Width+10;
Scrollbox1.VertScrollBar.Range := PaintBox1.Height+10;
if lpPoint.x>= (Scrollbox1.width/2) then
Scrollbox1.HorzScrollBar.Position := Round(lpPoint.x * iScale/100-Scrollbox1.width/2)+2
else
Scrollbox1.HorzScrollBar.Position := Round(lpPoint.x * iScale/100-PaintBox1.Width)+2;
if lpPoint.y> Scrollbox1.Height/2 then
Scrollbox1.VertScrollBar.Position := Round(lpPoint.y * iScale/100-Scrollbox1.height/2)+2
else
Scrollbox1.VertScrollBar.Position := Round(Scrollbox1.height/2-lpPoint.y * iScale/100)+2
end else
begin
iScale:=100;
//image1.picture := nil;
SetPreviewSize;
SetPreviewPpi;
Scrollbox1.HorzScrollBar.Range := PaintBox1.Width;
Scrollbox1.VertScrollBar.Range := PaintBox1.Height;
Scrollbox1.HorzScrollBar.Position := 0;
Scrollbox1.VertScrollBar.Position := 0;
PaintBox1.Top:=5;
FRM_Preview.PaintBox1.Left:= (FRM_Preview.ScrollBox1.Width-FRM_Preview.PaintBox1.Width) div 2;
end;
//DrawOnePage(PaintBox1.Canvas.Handle, PaintBox1.Canvas,iPageWidth,iPageHeight,iLeftMargin,iTopMargin,iRightMargin,iBottomMargin, nFooterMargin, true,PrePpiX,PrePpiY, sMainDir+'/Temp/'+IntToStr(iPageNumber)+'.tmp', iScale);
PaintBox1.Visible := true;
ScrollBox1.Visible:=true;
LockWindowUpdate(0);
PostMessage(Handle, WM_ERASEBKGND, ClientHandle, 0);
end;
请问各位还有什么好的建议?