Chrissy.
> How do I determine, in code, what lines are displayed in
> a Rich Edit control?
>
> What I want is three Rich Edit controls, with lines that are
> relates, to scroll at the same time. I thought that I could
> scroll all three when one is scrolled but cannot work out
> how to do this.
Here is some I code I use to make a RichEdit display specific lines etc. I
can't remember where I scrounged/hacked it from.
This gets the line and column of the current cursor posistion
Ln := DocRichEdit.Perform(EM_LINEFROMCHAR, DocRichEdit.SelStart, 0);
LnStart := DocRichEdit.Perform(EM_LINEINDEX, Ln, 0);
col := DocRichEdit.SelStart - LnStart;
This positions a specific line in the middle of the RE
function TfrmMain.GetMaxVisible(ThisRe : TRichEdit) : integer;
var
richDC : HDC;
tm : TTextMetric;
begin
if ThisRE.visible then
begin
richDC := GetDC(ThisRE.Handle);
SelectObject(richDC, ThisRE.Font.Handle);
GetTextMetrics(richDC, tm);
ReleaseDC(ThisRE.Handle, richDC);
result := ThisRE.clientheight div tm.tmheight;
end
else
result := -1;
end;
procedure TfrmMain.ShowLineMiddle(ThisRE : TRichEdit; ShowLine : integer);
var // scroll RichEdit (if necessary) to act like a TMemo
TopVisible, vertsize, TopRow : Integer;
begin
vertsize := GetMaxVisible(ThisRE);
if vertsize < 0 then
exit; // RE comp not visible
if ThisRE.lines.count > vertsize then
begin //more lines than vert size, scroll
TopRow := ShowLine - vertsize div 2;
if TopRow < 0 then
TopRow := 0; // range checks
if TopRow > ThisRE.lines.count then
TopRow := ThisRE.lines.count -1;
TopVisible := ThisRE.perform(EM_GETFIRSTVISIBLELINE, 0,0);
ThisRE.Perform(EM_LINESCROLL, 0, TopRow - TopVisible);
end;
end;
This should help you do what you want.
Paul
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"