Move TRichEdit Caretpos

Is there a way to reposition a carriage in a pixel?

I would like to move the call sign every time I move the mouse.

as:

OnMouseMove: MoveCaretPos (X, Y);

+3
source share
1 answer

No, you cannot set the position of the carriage at a specific point; instead, you must set the carriage to the position of the character. To do this, you must use the message EM_CHARFROMPOSto extract the closest character to the specified point and then set the value returned to SelStart.

Check out 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;
+7
source

All Articles