⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 与Action相结合,可以解决中文件显示乱码
💻 CPP
字号:
/*=============================================================================}
{ This demo shows how to scroll to specified position of document using        }
{ special invisible labels - "checkpoints"                                     }
{ Key methods and properties:                                                  }
{ - AddNamedCheckpoint;                                                        }
{ - GetCheckpointByNo, FindCheckpointByName;                                   }
{ - GetCheckpointY, GetCheckpointYEx;                                          }
{ - ScrollTo                                                                   }
{ - Options (rvoShowCheckpoints)                                               }
{=============================================================================*/
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma link "RichView"
#pragma link "RVScroll"
#pragma link "RVStyle"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  for (int i=1; i<4; i++)
  {
    RichView1->AddNamedCheckpoint(AnsiString("C")+IntToStr(i));
    RichView1->AddFmt("Chapter %d", ARRAYOFCONST((i)), 1,1);
    for (int j=0; j<30; j++)
    {
      RichView1->AddNL("Bla - bla - bla - bla - bla - bla - bla - bla"
                      "- bla - bla - bla - bla - bla - bla - bla - bla",0,0);
    }
  }
  RichView1->AddNamedCheckpoint("END");
  RichView1->Format();
  /*
    Comments:

    Checkpoints are not items. They are special additional information,
    associated with any item.
    (in older, freeware versions, checkpoints were items)
    But checkpoint can be added like any other item using Add*** methods:
    AddNamedCheckpoint, AddCheckpoint, AddNamedCheckpointEx, and some other.

    AddNamedCheckpoint("") == AddCheckpoint

    Checkpoint added with any of these methods will be associated with next
    added item (if no items added after it, checkpoints becomes special
    end-of-text checkpoint which is not associated with any item)

    Do not try to add checkpoints one after another without items between them
    (it's impossible, and causes the exception)
  */
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
  // toggles checkpoints visibility
  if (CheckBox1->Checked)
    RichView1->Options << rvoShowCheckpoints;
  else
    RichView1->Options >> rvoShowCheckpoints;
  RichView1->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  // GetCheckpointByNo(checkpoint index) - returns value of type TCheckpointData,
  // identifying checkpoint
  TCheckpointData CheckpointData = RichView1->GetCheckpointByNo(0);
  // GetCheckpointYEx returns Y coordinate of checkpoint
  int Y = RichView1->GetCheckpointYEx(CheckpointData);
  // ScrollTo - scrolls to specified Y coordinate
  RichView1->ScrollTo(Y);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  // The same actions, more compact
  RichView1->ScrollTo(RichView1->GetCheckpointYEx(RichView1->GetCheckpointByNo(1)));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
  // Even more compact
  RichView1->ScrollTo(RichView1->GetCheckpointY(2));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
  // We can use checkpoint name to find it
  RichView1->ScrollTo(
     RichView1->GetCheckpointYEx(
       RichView1->FindCheckpointByName("END")
                                )
                      );
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -