关于label换行的一个有关问题
关于label换行的一个问题
固定label2的宽度,实现label2显示的文本自行换行:
Label2.WordWrap:= True;
label2.AutoSize :=True;
label2.Constraints.MaxHeight :=300;
label2.Constraints.MinWidth :=200;
label2.Constraints.Maxwidth :=200;
label2.Caption :='Although no Chinese company was listed in the top three most desirable employers in industries surveyed, the popularity gap between State-owned firms and foreign companies is narrowing, the survey said.';
label2显示如下:
Although no Chinese company was listed
in the top three most desirable employers
in industries surveyed, the popularity gap
between State-owned firms and foreign
companies is narrowing, the survey said.
怎么能分别得到每一行的文本呢?
比如,第一行是: Although no Chinese company was listed
第二行是: in the top three most desirable employers
------最佳解决方案--------------------
有个最简单的办法,添加一个memo,属性设为不显示,克隆label2的属性和caption, 这样通过memo1.lines[0].....来获取,大概下面这样
------其他解决方案--------------------
计算字符宽度自己截取试试
------其他解决方案--------------------
一共多少个字符,Label的宽带,不过,应该确认下,一个字符在屏幕上是占多少个像素!
------其他解决方案--------------------
自己计算。。
固定label2的宽度,实现label2显示的文本自行换行:
Label2.WordWrap:= True;
label2.AutoSize :=True;
label2.Constraints.MaxHeight :=300;
label2.Constraints.MinWidth :=200;
label2.Constraints.Maxwidth :=200;
label2.Caption :='Although no Chinese company was listed in the top three most desirable employers in industries surveyed, the popularity gap between State-owned firms and foreign companies is narrowing, the survey said.';
label2显示如下:
Although no Chinese company was listed
in the top three most desirable employers
in industries surveyed, the popularity gap
between State-owned firms and foreign
companies is narrowing, the survey said.
怎么能分别得到每一行的文本呢?
比如,第一行是: Although no Chinese company was listed
第二行是: in the top three most desirable employers
------最佳解决方案--------------------
有个最简单的办法,添加一个memo,属性设为不显示,克隆label2的属性和caption, 这样通过memo1.lines[0].....来获取,大概下面这样
var
i:integer;
begin
Label2.WordWrap:= True;
label2.AutoSize :=True;
label2.Constraints.MaxHeight :=300;
label2.Constraints.MinWidth :=200;
label2.Constraints.Maxwidth :=200;
label2.Caption :='Although no Chinese company was listed in the top three most desirable employers in industries surveyed, the popularity gap between State-owned firms and foreign companies is narrowing, the survey said.';
Memo1.Visible:=False;
Memo1.Width:=Label2.Width;
Memo1.WordWrap:=True;
Memo1.Text:=Label2.Caption;
for i:=0 to memo1.Lines.Count-1 do
ShowMessageFMT('第%d行: %s',[i+1,Memo1.Lines[i]]);
end;
------其他解决方案--------------------
计算字符宽度自己截取试试
------其他解决方案--------------------
一共多少个字符,Label的宽带,不过,应该确认下,一个字符在屏幕上是占多少个像素!
------其他解决方案--------------------
自己计算。。