Move TRichEdit Caretpos

纵饮孤独 提交于 2019-12-10 19:57:00

问题


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

i would like to move the care pos everytime i move the mouse mouse.

like:

Onmousemove: MoveCaretPos(X, Y);


回答1:


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;


来源:https://stackoverflow.com/questions/6197305/move-trichedit-caretpos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!