我在程序中动态为QRLabel赋值,我希望当QRLabel.Caption中的内容的长度到达QRLabel的右边界时,QRLabel能够自动折行显示。由于我不知道输入的中文何时总宽度会到达QRLabel的右边界,所以不知道在哪里插入#13,想问一下怎么才能让QRLabel自动让Caption中的值换行。

解决方案 »

  1.   

    设定QRLabel的AutoSize=false,AutoStretch=true,然后报width设定到你需要的宽度即可。
      

  2.   

    你可以在代码里实现
      QRLabel.Caption:='第一行'+#13+'第二行';
      

  3.   

    唉!我搞定了
    Procedure TForm1.Button1Click(Sender:TObject);
    var
        Str,nowStr,value:String;
        i,Rownum:integer;
    Begin
        rownum:=1;
        nowstr:='';
        value:='';
        Self.Font:=QRLabel1.Font;
        Str:='aaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbcccccccccccccccccccc';
        for i:=1 to Length(Str) do
        Begin
            if Canvas.TextWidth(nowstr+Str[i])>QRLabel1.width Then
            Begin
                nowstr:='';
                value:=value+#13;
                inc(Rownum);
                nowstr:=nowstr+str[i];
                value:=value+str[i];
            End
            else
            Begin
                nowstr:=nowstr+str[i];
                value:=value+str[i];
            end;
        End;
        QRLabel1.Caption:=value;
        QRLabel1.Height:=QRLabel1.Height*Rownum;
    End;