RichEdit get line from pixel position

899 views Asked by At

If I click inside a TRichEdit control, how can I get the Line index (I clicked on) from the mouse client coordinates?

In other words, how do I convert a client coordinate to a Line Index?

***EDIT I'm actually not clicking inside the TRichEdit control, I'm clicking in another control and need to synch with the TRichEdit control's line number.

1

There are 1 answers

0
Remy Lebeau On BEST ANSWER

Send EM_CHARFROMPOS and EM_LINEFROMCHAR messages to the RichEdit, eg:

POINTL pt = ...; // client coordinates
int pos = RichEdit1->Perform(EM_CHARFROMPOS, 0, (LPARAM)&pt);
int idx = RichEdit1->Perform(EM_LINEFROMCHAR, pos, 0);