Link to home
Create AccountLog in
Avatar of ejla51
ejla51

asked on

Manage scrolling in RichEdit

Hi,
a little problem again...
How to resolve CaretPos(x,y) at the FirstVisibleLine in the RichEdit?
I have resolved some parameters for the text area, see code below.

     
// -----------------------------------------------------------------------------
function TForm1.GetLastVisibleLine(Window:TMyMemo) : Integer;
Begin
  Result := GetFirstVisibleLine(Window) + LinesVisible(RxWindow1);
end;
// -----------------------------------------------------------------------------
function TForm1.GetFirstVisibleLine(Window: TMyMemo): Integer;
begin
 Result := Window.Perform(EM_GETFIRSTVISIBLELINE, 0, 0 );
end;
// -----------------------------------------------------------------------------
 function TForm1.LinesVisible(Window: TMyMemo): integer;
    Var
      OldFont : HFont;
      Hand : THandle;
      TM : TTextMetric;
      Rect  : TRect;
      tempint : integer;
    begin
      Hand := GetDC(Window.Handle);
      try
        OldFont := SelectObject(Hand, Window.Font.Handle);
        try
          GetTextMetrics(Hand, TM);
          Window.Perform(EM_GETRECT, 0, longint(@Rect));
          tempint := (Rect.Bottom - Rect.Top) div (TM.tmHeight + TM.tmExternalLeading);
        finally
          SelectObject(Hand, OldFont);
        end;
      finally
        ReleaseDC(Window.Handle, Hand);
      end;
      Result := tempint;
    end;
// -----------------------------------------------------------------------------

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ejla51
ejla51

ASKER

ok ... thanks for your reply.
This works fine just like the solution to my question - but, I was on the wrong track in my thoughts ... I accept this as a solution and will open a new question in a another, new thread!