OnSelectionChange (C++)
Description
This example requires a TStatusBar and a TRichEdit. The code within the form's OnCreate takes care of sizing the Rich Edit and setting the OnSelectionChange event to be handled by RichEdit1SelectionChange (or you can paste the code directly into the OnSelectionChange event handler.) As you type in the Rich Edit control, the current character location where the selection begins and ends displays in the status bar control.
Code
void __fastcall TForm1::RichEdit1SelectionChange(TObject *Sender)
{
StatusBar1->SimpleText = L" Selection Start: " + IntToStr(RichEdit1->SelStart) +
" Selection End: " + IntToStr(RichEdit1->SelStart + RichEdit1->SelLength);
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
wchar_t const *Path = L"..\\OVERVIEW.RTF";
RichEdit1->Lines->LoadFromFile(Path);
RichEdit1->Align = alClient;
RichEdit1->OnSelectionChange = RichEdit1SelectionChange;
StatusBar1->SimplePanel = True;
}