Show last row in TLabel

I have a fixed height TLabel and word wrap. The problem is that when the text of the inscription exceeds the height of the inscription, I do not see the last lines of the text. I am browsing the entire Internet for shortcut components that can scroll down and show the last lines of text that exceed the height of the text.

As you can see in this figure, line 7 is half-sized, and line 8 is not even shown:

enter image description here

I want line 1 to disappear or rise, and line 8 to be fully visible.

+4
source share
2 answers

You can override the virtual TLabel method DoDrawText. something like this (example using the class of interposers):

TLabel = class(StdCtrls.TLabel)
protected
  procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
end;

... 

procedure TLabel.DoDrawText(var Rect: TRect; Flags: Longint);
var
  R: TRect;      
  TextHeight: Integer;
begin
  if (Flags and DT_CALCRECT = 0) then
  begin
    R := ClientRect;
    Canvas.Font := Font;
    DrawText(Canvas.Handle, PChar(Text), -1, R, DT_EXPANDTABS or DT_CALCRECT or DT_WORDBREAK);        
    TextHeight := R.Bottom - R.Top;    
    if TextHeight > ClientHeight then
      Rect.Top := Rect.Top - (TextHeight - ClientHeight);
  end;
  inherited DoDrawText(Rect, Flags);
end;

enter image description here

+9
source

TScrollBox:

  • TScrollBox.

  • TLabel TScrollBox.

  • alTop.

enter image description here

+3

Source: https://habr.com/ru/post/1685853/


All Articles