Know how many lines there are in a TMemo  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 26/12/99

Tip accessed 476 times

 


Useful for calculate the screen capacity...



 procedure TForm1.Button1Click(Sender: TObject);

   function LineasVisibles(Memo: TMemo): integer;
    Var
      Oldfont  : HFont;       {the old font}
      DC       : THandle;     {Device context handle}
      i        : integer;     {loop variable}
      Tm       : TTextMetric; {text metric structure}
      TheRect  : TRect;
    begin
      DC := GetDC(Memo.Handle);
      try
        OldFont := SelectObject(DC, Memo.Font.Handle);
        try
          GetTextMetrics(DC, Tm);
          Memo.Perform(EM_GETRECT, 0, longint(@TheRect));
          Result := (TheRect.Bottom - TheRect.Top) div
             (Tm.tmHeight + Tm.tmExternalLeading);
        finally
          SelectObject(DC, Oldfont);
        end;
      finally
        ReleaseDC(Memo.Handle, DC);
      end;
    end;
 begin
   Label1.Caption:=IntToStr(LineasVisibles(Memo1));
 end;