I put a string value into a TMemo and give the control focus. The cursor
is positioned at the end of the TMemo.
Now I want to position the cursor at the start of the TMemo.
Does anybody know how I can do this?
Cheers,
Graham
This seems to work:
Memo1.SelStart := 0;
Memo1.SetFocus;
Charles Johnson
Gintaras Pikelis
Baltic Solutions
Some notes I did a little while ago on TMemo scrolling :-
If you just add lines to the TMemo (without BeginUpdate / EndUpdate), the
viewport scrolls to the last line added. However if you use BeginUpdate / add
lines / EndUpdate, then the viewport does not scroll.
If you want to position the viewport, you can then use the windows messages in
a Perform method to move the viewport. Some of the messages (with their
parameters) available are :-
(EM_Scroll, nScroll, 0) scrolls an amount defined by the second parameter
constant, the third parameter must be zero.
where nScroll is one of the constants SB_LINEDOWN, SB_LINEUP, SB_PAGEDOWN, or
SB_PAGEUP. The move is limited to those available, ie it does not scroll so
that the first or the last line is out of the viewport.
(EM_LineScroll, cxScroll, cyScroll)
where cxScroll and cyScroll are integers (+ve or -ve) to scroll characters
(cxScroll) or lines (cyScroll). The line move is limited to those available.
(EM_ScrollCaret, 0, 0) moves the viewport so that the caret is in the viewport.
where the second and third parameters must be zero.
Memo1.Perform(EM_SetSel, 0, 0); {move caret to top}
Memo1.Perform(EM_LineScroll, 0, Memo1.Lines.Count * -1); {move to top}
{or Memo1.Perform(EM_ScrollCaret, 0, 0); scroll caret into view}
Memo1.SetFocus;
Memo1.Perform(EM_SetSel, Memo1.GetTextLen, Memo1.GetTextLen); {move caret to
bottom}
Memo1.Perform(EM_LineScroll, 0, Memo1.Lines.Count); {move to bottom}
{or Memo1.Perform(EM_ScrollCaret, 0, 0); scroll caret into view}
Memo1.SetFocus;
Alan Lloyd
alang...@aol.com