Mirror

How to determine the screen coordinates of highlighted text in a TRichEdit (Views: 100)


Problem/Question/Abstract:

How can I determine the screen coordinates (x, y) of the highlighted text of a TRichEdit component?

Answer:

procedure TForm1.Button3Click(Sender: TObject);
var
  pt: TPoint;
begin
  with richedit1 do
  begin
    pt := point(0, 0);
    Perform(messages.EM_POSFROMCHAR, WPARAM(@pt), selstart);
    {pt is in client coordinates}
    label3.caption := Format('(%d, %d)', [pt.x, pt.y]);
    {convert to screen coordinates}
    pt := ClientToScreen(pt);
    label2.caption := Format('(%d, %d)', [pt.x, pt.y]);
  end;
end;

<< Back to main page