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

RichEdit

开发平台:

Delphi

  1. /*=============================================================================}
  2. { This demo shows how to scroll to specified position of document using        }
  3. { special invisible labels - "checkpoints"                                     }
  4. { Key methods and properties:                                                  }
  5. { - AddNamedCheckpoint;                                                        }
  6. { - GetCheckpointByNo, FindCheckpointByName;                                   }
  7. { - GetCheckpointY, GetCheckpointYEx;                                          }
  8. { - ScrollTo                                                                   }
  9. { - Options (rvoShowCheckpoints)                                               }
  10. {=============================================================================*/
  11. //---------------------------------------------------------------------------
  12. #include <vclvcl.h>
  13. #pragma hdrstop
  14. #include "Unit1.h"
  15. //---------------------------------------------------------------------------
  16. #pragma link "RichView"
  17. #pragma link "RVScroll"
  18. #pragma link "RVStyle"
  19. #pragma resource "*.dfm"
  20. TForm1 *Form1;
  21. //---------------------------------------------------------------------------
  22. __fastcall TForm1::TForm1(TComponent* Owner)
  23.     : TForm(Owner)
  24. {
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::FormCreate(TObject *Sender)
  28. {
  29.   for (int i=1; i<4; i++)
  30.   {
  31.     RichView1->AddNamedCheckpoint(AnsiString("C")+IntToStr(i));
  32.     RichView1->AddFmt("Chapter %d", ARRAYOFCONST((i)), 1,1);
  33.     for (int j=0; j<30; j++)
  34.     {
  35.       RichView1->AddNL("Bla - bla - bla - bla - bla - bla - bla - bla"
  36.                       "- bla - bla - bla - bla - bla - bla - bla - bla",0,0);
  37.     }
  38.   }
  39.   RichView1->AddNamedCheckpoint("END");
  40.   RichView1->Format();
  41.   /*
  42.     Comments:
  43.     Checkpoints are not items. They are special additional information,
  44.     associated with any item.
  45.     (in older, freeware versions, checkpoints were items)
  46.     But checkpoint can be added like any other item using Add*** methods:
  47.     AddNamedCheckpoint, AddCheckpoint, AddNamedCheckpointEx, and some other.
  48.     AddNamedCheckpoint("") == AddCheckpoint
  49.     Checkpoint added with any of these methods will be associated with next
  50.     added item (if no items added after it, checkpoints becomes special
  51.     end-of-text checkpoint which is not associated with any item)
  52.     Do not try to add checkpoints one after another without items between them
  53.     (it's impossible, and causes the exception)
  54.   */
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::CheckBox1Click(TObject *Sender)
  58. {
  59.   // toggles checkpoints visibility
  60.   if (CheckBox1->Checked)
  61.     RichView1->Options << rvoShowCheckpoints;
  62.   else
  63.     RichView1->Options >> rvoShowCheckpoints;
  64.   RichView1->Invalidate();
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::Button1Click(TObject *Sender)
  68. {
  69.   // GetCheckpointByNo(checkpoint index) - returns value of type TCheckpointData,
  70.   // identifying checkpoint
  71.   TCheckpointData CheckpointData = RichView1->GetCheckpointByNo(0);
  72.   // GetCheckpointYEx returns Y coordinate of checkpoint
  73.   int Y = RichView1->GetCheckpointYEx(CheckpointData);
  74.   // ScrollTo - scrolls to specified Y coordinate
  75.   RichView1->ScrollTo(Y);
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TForm1::Button2Click(TObject *Sender)
  79. {
  80.   // The same actions, more compact
  81.   RichView1->ScrollTo(RichView1->GetCheckpointYEx(RichView1->GetCheckpointByNo(1)));
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::Button3Click(TObject *Sender)
  85. {
  86.   // Even more compact
  87.   RichView1->ScrollTo(RichView1->GetCheckpointY(2));
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TForm1::Button4Click(TObject *Sender)
  91. {
  92.   // We can use checkpoint name to find it
  93.   RichView1->ScrollTo(
  94.      RichView1->GetCheckpointYEx(
  95.        RichView1->FindCheckpointByName("END")
  96.                                 )
  97.                       );
  98. }
  99. //---------------------------------------------------------------------------