开发者

Move TRichEdit Caretpos

开发者 https://www.devze.com 2023-03-09 11:01 出处:网络
is there a way to change the caret position in pixel? i would like to move the car开发者_JAVA技巧e pos everytime i move the mouse mouse.

is there a way to change the caret position in pixel?

i would like to move the car开发者_JAVA技巧e pos everytime i move the mouse mouse.

like:

Onmousemove: MoveCaretPos(X, Y);


No, you cannot set the position of the caret in a specific point, instead you must set the caret in a character position. To do this you must use the EM_CHARFROMPOS message to retrieve the closest character to a specified point and then set the value returned to the SelStart property.

Check this sample

procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
 APoint  : TPoint;
 Index   : Integer;
begin
   APoint := Point(X, Y);
   Index :=  SendMessage(TRichEdit(Sender).Handle,EM_CHARFROMPOS, 0, Integer(@APoint));
   if Index<0 then Exit;
   TRichEdit(Sender).SelStart:=Index;
end;
0

精彩评论

暂无评论...
验证码 换一张
取 消