2009. június 7., vasárnap

How to determine the screen coordinates of highlighted text in a TRichEdit


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;

Nincsenek megjegyzések:

Megjegyzés küldése