Board index » delphi » Row-Col in TMemo
Jim Reiley
![]() Delphi Developer |
Jim Reiley
![]() Delphi Developer |
Row-Col in TMemo2003-12-15 09:08:37 AM delphi152 How can I find out the row and column the cursor is at on a TMemo in real time? Jim R |
Rob Kennedy
![]() Delphi Developer |
2003-12-15 02:44:49 PM
Re:Row-Col in TMemo
Jim Reiley writes:
QuoteHow can I find out the row and column the cursor is at on a TMemo in Rob |
kbarthelmess
![]() Delphi Developer |
2003-12-15 08:00:48 PM
Re:Row-Col in TMemo
Jim Reiley <XXXX@XXXXX.COM>writes:
QuoteHow can I find out the row and column the cursor is at on a TMemo in The caret position (in characters, not row / columns) when no text is selected can be obtained from the SelStart property. When text is selected, SelLength will be non-zero and the caret can be at either the SelStart value or SelStart + SelLength position, depending on the direction in which the user selected the text. You can use the EM_GETLINEFROMCHAR to get the actual line number based on the character position. But note that soft line breaks, variable width fonts make this sort of questionably useful. The cursor (mouse) position can be convered to a row/column with an EM_CHARPOS message. Again, this may or may not be useful. If this doesn't help, please followup telling us exactly what you want to do - the possibilities are too many to cover. Good luck. Kurt |
Jim Reiley
![]() Delphi Developer |
2003-12-15 10:14:28 PM
Re:Row-Col in TMemo
Hi,
I need to know the line(row) and the position(col) within the line, and I need to be able to set the cursor to these positions. This is in a straight text memo, no formatting or font changes or anything like that. If I can not get the row position, then I can live with the line number. The memo is actually a richedit type memo. I'd use a regular memo except I need to be able to do overwrites as well as inserts. . Thanks, Jim R "Kurt Barthelmess (TeamB)" writes: QuoteJim Reiley <XXXX@XXXXX.COM>writes: |
kbarthelmess
![]() Delphi Developer |
2003-12-15 11:47:31 PM
Re:Row-Col in TMemo
Jim Reiley <XXXX@XXXXX.COM>writes:
QuoteI need to know the line(row) and the position(col) within the line, and I var Pt: TPoint; ... { Get the client relative caret coordinates } SendMessage(RichEdit1.Handle, EM_POSFROMCHAR, Longint(@Pt), RichEdit1.SelStart); { Convert to screen coordinates } Pt := RichEdit1.ClientToScreen(Pt); { Move the cursor } SetCursorPos(Pt.X, Pt.Y); You'll notice that the cursor (probably an "I" bar) looks to be half way above the top of the line - it is. that is because the coordinate reported by the RichEdit is the top of the line and the "hot spot" of the cursor is in the middle of the "I" bar. You can add half of the font height to the Y coordinate (Pt.Y) in the call to SetCursorPos to make it look nicer. Good luck. Kurt |
Jim Reiley
![]() Delphi Developer |
2003-12-17 01:26:25 AM
Re:Row-Col in TMemo
Thanks.
Jim "Kurt Barthelmess (TeamB)" writes: QuoteJim Reiley <XXXX@XXXXX.COM>writes: |