|
TCustomRichViewEdit.OnMeasureCustomCaret |
Top Previous Next |
|
Allows to define size and position for custom caret. type TRVMeasureCustomCaretEvent = procedure (Sender: TCustomRichViewEdit; var Rect: TRect) of object; property OnMeasureCustomCaret: TRVMeasureCustomCaretEvent; (introduced in version 10) Custom caret is drawn if CustomCaretInterval>0. This event is called before each call to OnDrawCustomCaret. It allows to set your own size and position for the caret. The default size and position are the same as of the default system caret. The editor stores background under the Rect, it will be restored after the call to OnDrawCustomCaret. ExampleThis example defines the custom caret width. For non-text items, or at the end of item, it sets the caret width = default width + 10.For text items, it sets the caret width equal to width of character to the right of the caret. This example uses TMyForm.Canvas to calculate character width. procedure TMyForm.MyRichViewEditMeasureCustomCaret(Sender: TCustomRichViewEdit; var Rect: TRect); var s: String; begin Sender := Sender.TopLevelEditor; if Sender.CurItemStyle<0 then begin inc(Rect.Right, 10); exit; end; if Sender.OffsetInCurItem>=Sender.GetOffsAfterItem(Sender.CurItemNo) then begin inc(Rect.Right, 10); exit; end; s := Sender.GetItemText(Sender.CurItemNo); Canvas.Font.Assign(Sender.Style.TextStyles[Sender.CurItemStyle]); Rect.Right := Rect.Right+Canvas.TextWidth(s[Sender.OffsetInCurItem]); end; |