DelphiFAQ Home Search:

Have a TMemo/ TRichEdit scroll to the cursor position

 

comments12 comments. Current rating: 5 stars (7 votes). Leave comments and/ or rate it.

After placing the cursor at the desired position using the SelStart property,
you should use the EM_SCROLLCARET message to scroll the caret into view,
as shown in the piece of code below.

(To set the SelStart property to a x/y coordinate, also read this tip:
Access the current row/column of a TMemo.)

// scroll caret into view,
// the wParam, lParam parameters are ignored
SendMessage(Memo1.handle, EM_SCROLLCARET,0,0);

Comments:

2005-11-09, 05:03:05
daveb@cartoworld.com from South Africa  
rating
THanks !!!! That's just what i needed
2006-01-08, 20:07:37
p@ttersonm@rk(at)optusnet*com*au from Australia  
That was what I needed to! I used these lines to scroll to bottom of a log file:
RichEdit1.SelStart := MaxInt;
SendMessage(RichEdit1.handle, EM_SCROLLCARET,0,0);
2006-02-20, 04:21:52
anonymous from United Kingdom  
rating
very usefull - thanks
2006-03-31, 07:17:21
anonymous from Italy  
Many Thanks
2006-08-10, 08:48:27
anonymous from United Kingdom  
rating
I needed that! Thank you!
2006-10-09, 00:18:26
anonymous from Hungary  
THX man! You save my life
2006-12-14, 08:25:48
anonymous from United Kingdom  
nice
2007-06-11, 02:44:10
anonymous from Netherlands  
The EM_SCROLLCARET on Win2000+ doesn't work with the window minimized. Is there a way to solve this?
2008-10-19, 03:56:08
anonymous from Japan  
rating
Thank you - it was short, clear and solved the problem.
2009-08-27, 09:36:43
anonymous from Brazil  
rating
Thanks! Very simple and functional.
2009-08-27, 16:25:32
anonymous from Russian Federation  
rating
Thanks a lot, saved me a good deal of time!
2012-11-05, 04:59:14
z666zz666z@terra.es from Spain  
rating
I have a problem, i need to have in horizontal sync two TMemos...

I had tryied with WM_HSCROLL, etc... it is horrible to trap all, al lot of different traps, including WM_KEYDOWN, etc...

I think it could be a better solution... just make them to horizontal scroll to a position...

So on WM_PAINT (i know it is not the best place, but at least the simpleast)... set the scroll position to whatever is on the focused one (only if different to avoid recursivity)...

But how can i get / know the position of the top left first character visible?

I am thinking of a workarround like setting SelStart to such posittion and send EM_SCROLLCARET message... just as a try...

Maybe there is a better solution!!

I just need both TMemo be allways on horizontal sync... the top one with horizontal scrollbar hidden and both with vertical scroll bars visible.

Thanks!

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: