delphilinerichedittrichedit

Delphi RichEdit, get y-pixel start of an arbitrary line


I have a richedit containing lines using different fonts, styles, languages etc.

I am drawing in a gutter. I would like to start my drawing at the same y pixel position as the corresponding line.


Solution

  • Send the control an em_PosFromChar message. It returns the client coordinates of the character at the given index, although the documentation doesn't say what the coordinates represent (upper left corner, baseline center, or what). You're looking for the character's baseline.

    Use em_LineIndex to get a character index for a given line number, if you don't already know the index of a character you're interested in.