RAD Studio VCL Reference
|
Occurs when the current selection changes.
property OnSelectionChange: TNotifyEvent;
__property TNotifyEvent OnSelectionChange;
Write an OnSelectionChange event handler to respond to changes in the selected text. Changes in selection can occur when the user changes the selection using the mouse or keyboard, or when the selection is changed through the SelText property. Portions of the selection can be changed through the Lines property.
C++ Examples:
/* This example requires a TStatusBar and a TRichEdit. The code within the form's OnCreate will take 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 the selection begin and end will display in the status bar control. */ void __fastcall TForm1::RichEdit1SelectionChange(TObject *Sender) { StatusBar1->SimpleText = " Selection Start: " + IntToStr(RichEdit1->SelStart) + " Selection End: " + IntToStr(RichEdit1->SelStart + RichEdit1->SelLength); } void __fastcall TForm1::FormCreate(TObject *Sender) { char const *Path = "..\\OVERVIEW.RTF"; RichEdit1->Lines->LoadFromFile(Path); RichEdit1->Align = alClient; RichEdit1->OnSelectionChange = RichEdit1SelectionChange; StatusBar1->SimplePanel = True; }
Delphi Examples:
{ This example requires a TStatusBar and a TRichEdit. The code within the form's OnCreate will take 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 the selection begin and end will display in the status bar control. } procedure TForm1.RichEdit1SelectionChange(Sender: TObject); begin with RichEdit1 do begin StatusBar1.SimpleText := ' Selection Start: ' + IntToStr(SelStart) + ' Selection End: ' + IntToStr(SelStart + SelLength); end; end; procedure TForm1.FormCreate(Sender: TObject); const Path = 'OVERVIEW.RTF'; begin with RichEdit1 do begin Lines.LoadFromFile(Path); Align := alClient; OnSelectionChange := RichEdit1SelectionChange; end; StatusBar1.SimplePanel := True; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|