CnPack Forum


 
Subject: 忠实的CnPack控件的爱好者关于AAText的难问题
xjhwc
新警察
Rank: 1



UID 454
Digest Posts 0
Credits 2
Posts 2
点点分 2
Reading Access 10
Registered 2004-7-14
Status Offline
Post at 2005-11-18 15:22  Profile | Blog | P.M. 
忠实的CnPack控件的爱好者关于AAText的难问题

我在做触摸屏查询软件(BCB6.0),用到了AAText控件。客户给的比较大WORD文件,可能要3屏才可以显示完。我把WORD文件保存为TXT文件。在TXT文件中的标题前面加<Title1><Center>,在段落前面加<Text1><Left>,都是手动加的。
T_List=new TStringList();
T_List->LoadFromFile("e:\\touch\\files\\3.txt");
AAText1->Text->Lines->Clear();
for (int i=0;i<=18;i++)
{
AAText1->Text->Lines->Add(T_List->Strings[i]);
}
用AAText1->Text->Lines->Add(T_List->Strings[i])一行一行的添加TXT文件中的文字。AAText控件的大小是确定的,如何让AAText1刚显示满的时候,就不要在往AAText1中添加文字。如果按下“下一页”把第一屏清除,接者第一屏的最后的文字,再重新读一屏文字。
帮忙!就差这点了。
Top
croslq
新警察
Rank: 1



UID 1152
Digest Posts 0
Credits 48
Posts 41
点点分 48
Reading Access 10
Registered 2005-10-10
Status Offline
Post at 2005-11-18 18:26  Profile | Site | Blog | P.M.  | QQ
哈哈,你自已重新写三,
通过
TAALabel->TextHeight高度判断,从新做一个三
Top
xjhwc
新警察
Rank: 1



UID 454
Digest Posts 0
Credits 2
Posts 2
点点分 2
Reading Access 10
Registered 2004-7-14
Status Offline
Post at 2005-11-18 23:22  Profile | Blog | P.M. 
出点钱也可以。QQ:16107371
Top
drop
新警察
Rank: 1



UID 1239
Digest Posts 0
Credits 2
Posts 2
点点分 2
Reading Access 10
Registered 2005-11-5
Status Offline
Post at 2005-11-19 14:29  Profile | Blog | P.M. 
倒,我也正要问这个问题

怎么让AAFONT换行 显示

aafadetext1.Text.Lines.Add(aStream2.DataString);
aStream2.DataString的长度超过了200 而aafadetext1 只能一次完整显示20
Top
drop
新警察
Rank: 1



UID 1239
Digest Posts 0
Credits 2
Posts 2
点点分 2
Reading Access 10
Registered 2005-11-5
Status Offline
Post at 2005-12-6 00:43  Profile | Blog | P.M. 
问题已解决,晕哦,细心想一想就行了.
Top
zjy
管理员
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
Post at 2005-12-6 08:50  Profile | Site | Blog | P.M. 
针对您遇到的问题,可以使用以下代码来判断:



type
  TAATextAccess = class(TAAText);

// 返回 AAText 控件在加载 ALines 文本后实际显示的有效高度
function GetAATextHeight(AAText: TAAText; ALines: TStrings): Integer;
var
  i, j: Integer;
  WrapLines: TStrings;
  CurrText: string;
  CurrAlign: TAlignment;
  TextWidth: Integer;
  TextHeight: Integer;
  AWidth: Integer;
  xFree: Boolean;
  MaxCol: Integer;
begin
  Result := 0;
  WrapLines := TStringList.Create;
  try
    with TAATextAccess(AAText), AAText.Text do
    begin
      xFree := not WordWrap and AutoSize and (Align in [alNone, alLeft, alRight]);
      if xFree then AWidth := 0
      else AWidth := ClientWidth;

      AAFont.Canvas := Canvas;
      AAFont.Effect.Assign(FontEffect);
      Canvas.Font.Assign(Font);
      for i := 0 to ALines.Count - 1 do
      begin
        CurrText := ALines[i]; //当前处理字符串
        if LabelEffect = leOnlyALine then
        begin
          Canvas.Font.Assign(Font);
          AAFont.Effect.Assign(FontEffect);
        end;
        Fonts.Check(CurrText, Canvas.Font, AAFont.Effect); //检查字体标签
        Labels.Check(CurrText, CurrAlign); //检查用户标签
        TextWidth := AAFont.TextWidth(CurrText);

        if WordWrap and (TextWidth > AWidth) then //自动换行
        begin
          MaxCol := AWidth * Length(CurrText) div TextWidth;
          while AAFont.TextWidth(Copy(CurrText, 1, MaxCol)) > AWidth do
            Dec(MaxCol);
          WrapText(CurrText, WrapLines, MaxCol);
        end else if CurrText <> '' then
          WrapLines.Text := CurrText
        else
          WrapLines.Text := ' ';
         
        if xFree and (TextWidth > AWidth) then //确定宽度
        begin
          AWidth := TextWidth;
        end;

        for j := 0 to WrapLines.Count - 1 do
        begin
          CurrText := WrapLines[j];
          TextHeight := AAFont.TextHeight(CurrText + ' ');
          Inc(Result, TextHeight);
          if (i < ALines.Count - 1) or (j < WrapLines.Count - 1) then
            Inc(Result, Round(TextHeight * RowPitch / 100));
        end;
      end;
      
      Result := Result + 2 * Border;
    end;
  finally
    WrapLines.Free;
  end;
end;

使用时,将需要加载的文本先放到临时字符串列表中,逐行增加并调用该函数判断当前有效高度是否大于控件实际高度。

另外,如果在 BCB 下使用,可以将这个函数放到 AACtrls 单元或新建一个 pas 单元来调用。




Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
Top
weijxin
新警察
Rank: 1



UID 1435
Digest Posts 0
Credits 5
Posts 5
点点分 5
Reading Access 10
Registered 2005-12-7
Location 广州
Status Offline
Post at 2005-12-7 12:51  Profile | Blog | P.M.  | QQ
我也有问题。

请各位前辈帮帮忙,小弟当前在使有AAFONT的控件组,使用AATEXT的控件,这是个可支持多行文件的LABEL,且可以设置每一行文字的字体和大小,风格等。但当我想在程序里动态生成时,却发现以上说的那些功能都不能使用,请各位指点指点。在线等待。程序如下:
tmpaatext:=TAAText.Create(self);
   tmpaatext.Parent:=self;
   tmpaatext.Left:=10;
   tmpaatext.Top:=10;
   tmpaatext.Text.Lines.Add('新标签');
   tmpaatext.Show;
   tmpaatext.Fonts[0].Font.size:=18;//出错,不可以使用
请问,我如何才可以控制每行的字体的大小和颜色。
Top
 




All times are GMT++8, the time now is 2024-4-30 13:54

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.006862 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP