Delphi: Center Specific Line in TRichEdit by Scrolling
Posted
by Anagoge
on Stack Overflow
See other posts from Stack Overflow
or by Anagoge
Published on 2010-05-12T20:20:59Z
Indexed on
2010/05/12
20:24 UTC
Read the original article
Hit count: 257
I have a Delphi 2007 TRichEdit with several lines in it. I want to scroll the richedit vertically such that a specific line number if approximately centered in the visible/display area of the richedit. For example, I want to write the code for CenterLineInRichEdit in this example:
procedure CenterLineInRichEdit(Edit: TRichEdit; LineNum: Integer);
begin
...
Edit.ScrollTo(...);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
REdit: TRichEdit;
i: Integer;
begin
REdit := TRichEdit.Create(Self);
REdit.Parent := Self;
Redit.ScrollBars := ssVertical;
REdit.SetBounds(10, 10, 200, 150);
for i := 1 to 25 do
REdit.Lines.Add('This is line number ' + IntToStr(i));
CenterLineInRichEdit(REdit, 13);
end;
I looked into using the WM_VSCROLL message, and it allows scrolling up/down one line, etc. but not scrolling to center a specific line. I assume I would need to calculate the line height, the display area height, etc? Or is there an easier way?
© Stack Overflow or respective owner