Unit1.cpp
上传用户:daoqigc
上传日期:2021-04-20
资源大小:2795k
文件大小:3k
源码类别:

RichEdit

开发平台:

Delphi

  1. /*==============================================================================
  2. { Example: two ways of drawing RichView document onto Canvas                   }
  3. ==============================================================================*/
  4. //---------------------------------------------------------------------------
  5. #include <vclvcl.h>
  6. #pragma hdrstop
  7. #include "Unit1.h"
  8. #include "WMFCanvasWorkAround.hpp"
  9. //---------------------------------------------------------------------------
  10. #pragma link "RichView"
  11. #pragma link "RVScroll"
  12. #pragma link "RVStyle"
  13. #pragma link "RVReport"
  14. #pragma link "PtblRV"
  15. #pragma resource "*.dfm"
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19. : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25.   int i;
  26.   // For Example 1
  27.   RichView1->AddNL("This is a line of text",1,1);
  28.   for (i=0; i<20; i++)
  29.     RichView1->AddNL("This is a line of text",0,0);
  30.   RichView1->Format();
  31.   // For Example 2
  32.   RVReportHelper1->RichView->Style = RVStyle1;
  33.   RVReportHelper1->RichView->AddNL("This is a line of text",1,1);
  34.   for (i=0; i<20; i++)
  35.     RVReportHelper1->RichView->AddNL("This is a line of text",0,0);
  36. }
  37. //---------------------------------------------------------------------------
  38. #define VERYLARGEVALUE 0xFFFFFFF
  39. // Example 1
  40. void __fastcall TForm1::Button1Click(TObject *Sender)
  41. {
  42.   RichView1->HScrollPos = 0;
  43.   RichView1->VScrollPos = 0;
  44.   RichView1->Deselect();
  45.   RichView1->Invalidate();
  46.   int Width  = RichView1->RVData->DocumentWidth+RichView1->LeftMargin+RichView1->RightMargin;
  47.   int Height = RichView1->RVData->DocumentHeight;
  48.   TMetafile* wmf = new TMetafile;
  49.   wmf->Width  = Width;
  50.   wmf->Height = Height;
  51.   TMetafileCanvas* Canvas = (TMetafileCanvas*)CreateMetafileCanvas(wmf); // from WMFCanvasWorkAround unit
  52.   Canvas->Brush->Color = clWindow;
  53.   Canvas->FillRect(Rect(0,0,Width,Height));
  54.   RichView1->RVData->PaintTo(Canvas, Rect(0,0,VERYLARGEVALUE,VERYLARGEVALUE));
  55.   delete Canvas;
  56.   Image1->Picture->Graphic = wmf;
  57.   delete wmf;
  58. }
  59. //---------------------------------------------------------------------------
  60. // Example 2
  61. void __fastcall TForm1::Button2Click(TObject *Sender)
  62. {
  63.   int Width = 200;
  64.   RVReportHelper1->Init(this->Canvas, Width);
  65.   while (RVReportHelper1->FormatNextPage(VERYLARGEVALUE));
  66.   TMetafile* wmf = new TMetafile;
  67.   wmf->Width  = Width;
  68.   wmf->Height = RVReportHelper1->EndAt;
  69.   TMetafileCanvas* Canvas = (TMetafileCanvas*)CreateMetafileCanvas(wmf); // from WMFCanvasWorkAround unit
  70.   RVReportHelper1->DrawPage(1, Canvas, true, RVReportHelper1->EndAt);
  71.   delete Canvas;
  72.   Image2->Picture->Graphic = wmf;
  73.   delete wmf;
  74. }
  75. //---------------------------------------------------------------------------