关于多页预览的问题(100分)

  • 主题发起人 主题发起人 ArJianzeng
  • 开始时间 开始时间
A

ArJianzeng

Unregistered / Unconfirmed
GUEST, unregistred user!
大家好!!!我是个dephi的编程新手,最近接触到一个有关于打印预览的问题,不知那为大虾和高手肯帮帮忙...
具体代码如下:
procedure TForm1.buttonClick(Sender :TObject);
var
BlackImage , WhiteImage : TImage ;
intCapsX,intCapsY : Integer ;
intPageWidth,intPageHeight : Integer ;
intRowCounts ,intPianYi: Integer ;
intTextWidth,intTextHeight : Integer ;
intPageCount : Integer;
I , J , K , int : Integer ;
intTopText : String ;
//页头。
ListPrintTest : TStringList;
iCount :Integer;
intTextCount :Integer;
// X,Y,mapW,mapH : Integer;//用于{//*....*//}部分.
begin

ListPrintTest :=TStringList.Create ;
ListPrintTest.AddStrings(MainForm.RichEditor.Lines);
//坐标象素转换成英寸。
intCapsX :=GetDeviceCaps(Printer.Handle,LOGPIXELSX) ;
intCapsY :=GetDeviceCaps(Printer.Handle,LOGPIXELSY);
intPageWidth :=Printer.PageWidth *PixelsPerInch div (intCapsX);
//纸张每页宽度;
intPageHeight :=Printer.PageHeight*PixelsPerInch div (intCapsY);
//纸张每页高度;
intPianYi :=intPageHeight div intPageWidth;

ViewSize :=ViewSize div 100;

Canvas.Font.Size :=MainForm.RichEditor.Font.Size *ViewSize ;
intTextWidth:=Canvas.TextWidth ('啊');
intTextHeight:=Canvas.TextHeight ('啊');

intTextCount:=intPageHeight-(ScrollBox1.Top+80);
intRowCounts:=(intTextCount-60+intTextHeight) div (intTextHeight+intPianYi);// 每页行数;

intPageCount:=(ListPrintTest.Count-1) div intRowCounts;
//页数。

if ((ListPrintTest.Count-1) Mod intRowCounts)<>0 then
//遇到余数行。
intPageCount:=intPageCount+1;
if ((intRowCounts*intTextHeight+intPianYi) >= (intTextCount-60+intTextHeight))then

begin

intRowCounts :=(intPageHeight-intTextCount-60)div (intTextHeight+intPianYi);
;
intPageCount:=intPageCount+1;
end;


StartPrintDlg.FromPage:=1;
StartPrintDlg.MinPage :=1;
StartPrintDlg.MaxPage :=intPageCount;
StartPrintDlg.ToPage := intPageCount;


J:=0;
for I:= StartPrintDlg.FromPage to StartPrintDlg.ToPagedo

begin

Inc(J);
K:=(J-1)*(intPageHeight+40)+intTextHeight+10;
mapImage :=TImage.Create(self);
with mapImagedo
//底纹.
begin

Top :=0;
Left :=0;
Width :=(intPageWidth+50);
Height :=(intPageHeight+50)*intPageCount;
Canvas.Brush.Color :=ScrollBox1.Color ;
Canvas.Rectangle(0,0,width,Height);
IncrementalDisplay := True;
stretch := True ;
Transparent :=True;
Parent :=ScrollBox1 ;
Visible :=True;
Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'prCode06.bmp');
end;


//以下是画出底纹.
{//* mapw :=0;
mapH :=0;
for X :=0 to mapImage.Widthdo

begin

for Y :=0 to mapImage.Heightdo

begin

while (mapW <=mapImage.Width*(2+K) )and (mapH<=mapImage.Height*(2+K))do

with mapImage.Canvasdo

begin

pen.Width :=1;
pen.Style := psDot;
pen.Color :=clwhite ;
MoveTo(mapw,0);
LineTo(0,mapH);

inc(mapW,8);
inc(mapH,8);
end;

end;

end;

*//}
BlackImage:=TImage.Create (Self);
//生成预览面板;
with BlackImagedo

begin

Left:=intTextWidth+10;
Top:=K+10;
width:=intPageWidth*ViewSize;
Height:=intPageHeight*ViewSize;
Canvas.Brush.Color :=clBlack;
Canvas.Rectangle(0,0,Width,Height);
Parent:=ScrollBox1;
Enabled:=True;
end;


WhiteImage:=TImage.Create(Self);
with WhiteImagedo

begin

Left:=(intTextWidth+5);
Top:=(K+5);
Width:=(intPageWidth)*ViewSize;
Height:=intPageHeight*ViewSize;
Canvas.Brush.Color :=clWhite;
Canvas.Rectangle(0,0,width,Height);
Parent:=ScrollBox1;
Enabled:=True;
end;

intMovePos :=WhiteImage.Height;
intTopText :='源代码打印系统例程.';
//页眉。
WhiteImage.Canvas.Font.Name :='宋体';
WhiteImage.Canvas.Font.Size :=10;
intTextHeight:=WhiteImage.Canvas.TextHeight ('啊');
WhiteImage.Canvas.TextOut(60+intPianYi,60,intTopText);
//打印出页眉。
WhiteImage.Canvas.MoveTo(60,70+intTextHeight);
WhiteImage.Canvas.LineTo(intPageWidth-60,70+intTextHeight);
//画线条。


if StartPrinting=False then

begin

with WhiteImage.Canvasdo

begin

Font.Assign(MainForm.RichEditor.Font);
Font.Size :=(MainForm.RichEditor.Font.Size )*ViewSize;
intTextWidth:=Canvas.TextWidth ('啊');
intTextHeight:=Canvas.TextHeight ('啊');

if ListPrintTest.Count <> 0 then

begin

for int:=0 to (intRowCounts)do
//输出。
begin

TextOut(intTextWidth+intPianYi+60,int*intTextHeight+100,
ListPrintTest.Strings[0]);
ListPrintTest.Delete(0);
if ListPrintTest.Count <=0 then

ListPrintTest.Add('');
end;

end;

end;


以上运行后出现的情况是:
* 当预览显示一页时,底纹可以正常显示,但当显示到三页是会出现接近死机的现象,而且,显示出来后,预览页面只显示最后一页,其他的好象都被覆盖了.
* 为什么" Picture.LoadFromFile(ExtractFilePath (Application.ExeName)+'prCode06.bmp');"与加了{//*...*//}部分的运行效果是一样的???
 
各位大虾,帮帮忙吧,我这个,问题已经搁了很久了、
 
你是小弟吧,你的问题解决了没有?
 
接受答案了.
 

Similar threads

I
回复
0
查看
538
import
I
I
回复
0
查看
696
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部