I have a TLabel with fixed height and word wrap. The problem is that when the caption text exceeds the label's height, I can't see the last lines of text. I search entire internet for label components that can scroll down and show the last lines of text that exceeds the height of caption.
我有一个带有固定高度和单词包装的TLabel。问题是,当标题文本超过标签的高度时,我看不到最后一行文本。我搜索整个互联网的标签组件,可以向下滚动并显示超过标题高度的最后一行文本。
As you can see in this picture, line 7 is half visible and line 8 is not even shown:
正如你在图中看到的,第7行是可见的,第8行甚至没有显示:
I want line 1 to disappear or go up and line 8 be fully visible.
我想让第一行消失或上升,第8行完全可见。
2 个解决方案
#1
9
You can override TLabel's DoDrawText
virtual method. something like this (example using interposer class):
您可以覆盖TLabel的DoDrawText虚拟方法。类似这样的东西(例如使用interposer类):
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;
#2
#1
9
You can override TLabel's DoDrawText
virtual method. something like this (example using interposer class):
您可以覆盖TLabel的DoDrawText虚拟方法。类似这样的东西(例如使用interposer类):
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;