CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

如何选中richedit中的内容并打印出来?

楼主realprogrammer(决不停步)2002-07-06 12:38:53 在 Delphi / VCL组件开发及应用 提问

高手快来,100分! 问题点数:100、回复次数:7Top

1 楼netlib(河外孤星)回复于 2002-07-06 12:40:18 得分 2

richedit.printTop

2 楼Carfield(一只特别懒的猫)回复于 2002-07-06 12:42:23 得分 2

可以用QuickReport的QRRichEdit控件打印RichEdit中的内容  
  QRRichEdit.ParaentRichEdit:=RichEdit1;Top

3 楼floattofool(foolish)回复于 2002-07-06 12:54:16 得分 90

哈哈,中招,快快给分!  
   
  Printing   rich   edit   selection   using   EM_FORMATRANGE:  
   
  procedure   TForm1.Button2Click(Sender:   TObject);  
  Var  
      printarea:   Trect;  
      richedit_outputarea:   TRect;  
      printresX,   printresY:   Integer;  
      fmtRange:   TFormatRange;  
      nextChar   :   Integer;  
      S:   String;  
  Begin  
      Printer.beginDoc;  
      try  
          With   Printer.Canvas   Do   Begin  
              printresX   :=   GetDeviceCaps(   handle,   LOGPIXELSX   );  
              printresY   :=   GetDeviceCaps(   handle,   LOGPIXELSY   );  
              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   bottom  
  margin  
                            );  
   
              //   Define   a   rectangle   for   the   rich   edit   text.   The   height   is   set   to   the  
              //   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   *   1440   div   printresX,  
                              printarea.top   *   1440   div   printresY,  
                              printarea.right   *   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   handle  
              fmtRange.hdcTarget   :=   Handle;           //   ditto  
              fmtRange.rc   :=   richedit_outputarea;  
              fmtRange.rcPage   :=  
                  Rect(   0,   0,  
                              Printer.PageWidth   *   1440   div   printresX,  
                              Printer.PageHeight   *   1440   div   printresY   );  
   
              //   set   range   of   characters   to   print   to   selection  
              fmtRange.chrg.cpMin   :=   richedit1.selstart;  
              fmtRange.chrg.cpMax   :=   richedit1.selStart   +   richedit1.sellength   -1;  
   
              //   remove   characters   that   need   not   be   printed   from   end   of   selection.  
              //   failing   to   do   so   screws   up   the   repeat   loop   below.  
              S:=   richedit1.SelText;  
              While   (fmtRange.chrg.cpMax   >   0   )   and  
                          (S[fmtRange.chrg.cpMax]   <=   '   ')  
              Do   Dec(fmtRange.chrg.cpMax);  
   
              Repeat  
                  //   Render   the   text  
                  nextChar   :=   richedit1.Perform(   EM_FORMATRANGE,   1,  
                                                Longint(@fmtRange));  
                  If   nextchar   <   fmtRange.chrg.cpMax   Then   Begin  
                      //   more   text   to   print  
                      printer.newPage;  
                      fmtRange.chrg.cpMin   :=   nextChar;  
                  End;   {   If   }  
              Until   nextchar   >=   fmtRange.chrg.cpMax;  
   
              //   Free   cached   information  
              richedit1.Perform(   EM_FORMATRANGE,   0,   0);  
          End;  
      finally  
          Printer.EndDoc;  
      end;  
  end;  
   
  The   richedit1.perform(   EM_FORMATRANGE   call   returns   the   index   of   the   last  
  character   that   could   be   fitted   into   the   passed   fmtrange.rc,   +   1.   So   if  
  multiple   pages   are   required   one   repeats   with   fmtrange.chrg.cpMin   set   to  
  this   value,   until   all   characters   have   been   printed.  
   
  Top

4 楼floattofool(foolish)回复于 2002-07-06 12:55:09 得分 2

哈哈,中招,快快给分!  
   
  Printing   rich   edit   selection   using   EM_FORMATRANGE:  
   
  procedure   TForm1.Button2Click(Sender:   TObject);  
  Var  
      printarea:   Trect;  
      richedit_outputarea:   TRect;  
      printresX,   printresY:   Integer;  
      fmtRange:   TFormatRange;  
      nextChar   :   Integer;  
      S:   String;  
  Begin  
      Printer.beginDoc;  
      try  
          With   Printer.Canvas   Do   Begin  
              printresX   :=   GetDeviceCaps(   handle,   LOGPIXELSX   );  
              printresY   :=   GetDeviceCaps(   handle,   LOGPIXELSY   );  
              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   bottom  
  margin  
                            );  
   
              //   Define   a   rectangle   for   the   rich   edit   text.   The   height   is   set   to   the  
              //   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   *   1440   div   printresX,  
                              printarea.top   *   1440   div   printresY,  
                              printarea.right   *   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   handle  
              fmtRange.hdcTarget   :=   Handle;           //   ditto  
              fmtRange.rc   :=   richedit_outputarea;  
              fmtRange.rcPage   :=  
                  Rect(   0,   0,  
                              Printer.PageWidth   *   1440   div   printresX,  
                              Printer.PageHeight   *   1440   div   printresY   );  
   
              //   set   range   of   characters   to   print   to   selection  
              fmtRange.chrg.cpMin   :=   richedit1.selstart;  
              fmtRange.chrg.cpMax   :=   richedit1.selStart   +   richedit1.sellength   -1;  
   
              //   remove   characters   that   need   not   be   printed   from   end   of   selection.  
              //   failing   to   do   so   screws   up   the   repeat   loop   below.  
              S:=   richedit1.SelText;  
              While   (fmtRange.chrg.cpMax   >   0   )   and  
                          (S[fmtRange.chrg.cpMax]   <=   '   ')  
              Do   Dec(fmtRange.chrg.cpMax);  
   
              Repeat  
                  //   Render   the   text  
                  nextChar   :=   richedit1.Perform(   EM_FORMATRANGE,   1,  
                                                Longint(@fmtRange));  
                  If   nextchar   <   fmtRange.chrg.cpMax   Then   Begin  
                      //   more   text   to   print  
                      printer.newPage;  
                      fmtRange.chrg.cpMin   :=   nextChar;  
                  End;   {   If   }  
              Until   nextchar   >=   fmtRange.chrg.cpMax;  
   
              //   Free   cached   information  
              richedit1.Perform(   EM_FORMATRANGE,   0,   0);  
          End;  
      finally  
          Printer.EndDoc;  
      end;  
  end;  
   
  The   richedit1.perform(   EM_FORMATRANGE   call   returns   the   index   of   the   last  
  character   that   could   be   fitted   into   the   passed   fmtrange.rc,   +   1.   So   if  
  multiple   pages   are   required   one   repeats   with   fmtrange.chrg.cpMin   set   to  
  this   value,   until   all   characters   have   been   printed.  
   
  Top

5 楼codingfans(Jaklly)回复于 2002-07-06 13:08:24 得分 2

看不明白,UP!Top

6 楼johnsonrao(johnson)回复于 2002-07-06 14:05:47 得分 2

同意floattofool(foolish)Top

相关问题

  • richedit的内容怎么实现保存,打印,打印预览,
  • 高分求RichEdit里的内容如何打印问题!!
  • RichEdit删除选中文本????
  • 调用哪个方法能让RichEdit中显示OpenDialog选中的文本文件的内容.
  • 请问,如何从RichEdit控件中获取当前选中内容的RTF文本
  • 对话框中,richedit控件中的内容如何实现打印,打印预览?
  • Richedit选中的中文变色问题
  • 如何实现,在两个RichEdit编辑框中:用鼠标选中一个编辑框中的部分内容然后拖动到另一个编辑框?
  • 如何选中datawindow column中的内容
  • 如何取得DropDownListBox选中的内容?@#$

关键词

  • fmtrange
  • printresy
  • printresx
  • richedit
  • printarea
  • chrg
  • cpmax
  • printer
  • formatrange
  • inch

得分解答快速导航

  • 帖主:realprogrammer
  • netlib
  • Carfield
  • floattofool
  • floattofool
  • codingfans
  • johnsonrao

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo