本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告
================

注会练习软件
http://www.cpasoft.com.cn
我的注会软件官网

http://blog.163.com/abc7105@126/

 

 


哈哈,热爱快“过气”的DELPHI


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:注册会计师(注会)练习软件
日志总数:398
评论数量:116
留言数量:27
访问次数:3273588
建立时间:2005年6月6日




richedit的打印完整代码(delphi)
软件技术

吕向阳 发表于 2009/2/24 21:52:50

下面加色的部分特别注意加上,网上的文章都不能完全成功,最后试了老半天才成 unit tesy; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls, ComCtrls, Printers,richedit; type  TCharrange = packed record    cpMin: LongInt;    cpMax: LongInt;  end; type  TFormatRange = packed record    hdc: HDC;    hdcTarget: HDC;    rc: TRect;    rcPage: TRect;    chrg: TCharrange;  end;type  TForm1 = class(TForm)    RichEdit1: TRichEdit;    Button1: TButton;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    { Private declarations }  public    { Public declarations }  end; var  Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject);var  printarea: Trect;  x, y: Integer;  richedit_outputarea: TRect;  printresX, printresY: Integer;  fmtRange: TFormatRange;begin  Printer.beginDoc;  try    with Printer.Canvas do begin      printresX := GetDeviceCaps(handle, LOGPIXELSX);      printresY := GetDeviceCaps(handle, LOGPIXELSY);      Font.Name := 'Arial';      Font.Size := 14;      Font.Style := [fsBold];      printarea :=        Rect(printresX, // 1 inch left margin        printresY * 3 div 2, // 1.5 inch top margin        Printer.PageWidth - printresX, // 1 inch right margin        Printer.PageHeight - printresY * 3 div 2 // 1.5 inch bottommargin        );      x := printarea.left;      y := printarea.top;      TextOut(x, y, 'A TRichEdit print example');      y := y + TextHeight('Ag');      Moveto(x, y);      Pen.Width := printresY div 72; // 1 point      Pen.Style := psSolid;      Pen.Color := clBlack;      LineTo(printarea.Right, y);      Inc(y, printresY * 5 div 72);         // Define a rectangle for the rich edit text. The height is set tothe        // maximum. But we need to convert from device units to twips,        // 1 twip = 1/1440 inch or 1/20 point.      richedit_outputarea :=        Rect((printarea.left + 2) * 1440 div printresX,        y * 1440 div printresY,        (printarea.right - 4) * 1440 div printresX,        (printarea.bottom) * 1440 div printresY);         // Tell rich edit to format its text to the printer. First set        // up data record for message:      fmtRange.hDC := Handle; // printer canvas handle      fmtRange.hdcTarget := Handle; // ditto      fmtRange.rc := richedit_outputarea;      fmtRange.rcPage :=        Rect(0, 0,        Printer.PageWidth * 1440 div printresX,        Printer.PageHeight * 1440 div printresY);         // the following lines select the text to print, in this case        // the complete content of the rich edit control.      fmtRange.chrg.cpMin := 0;      fmtRange.chrg.cpMax := richedit1.GetTextLen - 1;         // first measure the text, to find out how high the format rectangle        // will be. The call sets fmtrange.rc.bottom to the actual height        // required, if all characters in the selected range will fit into        // a smaller rectangle,      richedit1.Perform(EM_FORMATRANGE, 0, Longint(@fmtRange));         // Draw a rectangle around the format rectangle      Pen.Width := printresY div 144; // 0.5 points      Brush.Style := bsClear;      Rectangle(printarea.Left, y - 2, printarea.right,        fmtrange.rc.bottom * printresY div 1440 + 2);         // Now render the text      richedit1.Perform(EM_FORMATRANGE, 1, Longint(@fmtRange));        // and print it      richedit1.Perform(EM_DISPLAYBAND, 0, Longint(@fmtRange.rc));      y := fmtrange.rc.bottom * printresY div 1440 + printresY * 5 div 72;         // Free cached information      richedit1.Perform(EM_FORMATRANGE, 0, 0);      TextOut(x, y, 'End of example.');    end;  finally    Printer.EndDoc;  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  richedit1.Lines.LoadFromFile('d:\readme.txt');end; end.  事实上本代码仍不完善,只能打印第一页,期望能完成全部打印


阅读全文(1740) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.234 second(s), page refreshed 144809161 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号