本帖最后由 u010932630 于 2013-08-22 17:29:40 编辑

解决方案 »

  1.   

    用了一种比较笨的办法,希望能给你带来灵感
    function MyFormat(const AStr: String; AWidth: Integer; ADelimiter: char = ' '): String;
    var
      oLst: TStrings;
      I: Integer;
    begin
      Result := '';
      oLst := TStringList.Create;
      try
        oLst.Delimiter := ADelimiter;
        oLst.DelimitedText  := AStr;
        for I := 0 to OLst.Count - 1 do
          Result := Result + Format('%-' + IntTostr(AWidth) + 's', [OLst[i]]);
      finally
        oLst.Free;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
    begin
      RichEdit1.Font.Name := '新宋体';//可能你的问题就出在这里
      for I := 0 to RichEdit1.Lines.Count - 1 do
        RichEdit1.Lines[i] := MyFormat(RichEdit1.Lines[i], 16);
    end;
      

  2.   


    谢谢xiaojun5556,列是对齐了,但出现的问题是有的字符显示不正常,有的字变成了□。
      

  3.   

    这个是比较容易实现,可编辑文字就不方便了,不知各位大侠是否还有其他方法,不知道能不能在RichEdit里某行的指定坐标位置(坐标已知)插入文字,如果可以的话就好了。
      

  4.   

    这个是比较容易实现,可编辑文字就不方便了,不知各位大侠是否还有其他方法,不知道能不能在RichEdit里某行的指定坐标位置(坐标已知)插入文字,如果可以的话就好了。
    编辑文字哪儿不方便了
      

  5.   

    这个是比较容易实现,可编辑文字就不方便了,不知各位大侠是否还有其他方法,不知道能不能在RichEdit里某行的指定坐标位置(坐标已知)插入文字,如果可以的话就好了。
    编辑文字哪儿不方便了TStringGrid不适用目前的项目,除非TStringGrid可以拆分单元格差不多。
      

  6.   

    或者可以自己写一下吧。想了想,有个思路,不知道对不对,LZ研究下吧。
    1、把RichEdit1.Lines.Text按行储存到数组str1里面
    2、通过比较,找出每一列的最长,储存到str2里面。
    3、把数组str1里面的字符排版(比如说去掉空格,每个单词之间加上‘-’),每一组词的长度,按照str2里 面的长度设置。
    4、按行,把str1数据赋值给RichEdit1
    这样应该就应该达到LZ要求了吧
      

  7.   

    要的是这样的效果,求救各位XDJM了:http://img.bbs.csdn.net/upload/201308/25/1377415813_212512.jpg
      

  8.   

    我用这个来排版,但老对不直,帮我看看问题出在哪里?for h:= 0 to high(sortstr) do
    begin
           //提取字符串
           strpk:=sortstr[h];
           strpk1:=sortstr1[h]+'rrrr';
           strpk2:='kkkkkkkk';
           strpk3:='kkk';       //校正位置
           strp:=strp+strpk;
           strp1:=strp1+strpk1;
           strp2:=strp2+strpk2;
           strp3:=strp3+strpk3;       //计算最长列
           t:=label1.Canvas.TextWidth(strp);//取列字符串宽度(像素)
           t1:=label1.Canvas.TextWidth(strp1);
           t2:=label1.Canvas.TextWidth(strp2);
           t3:=label1.Canvas.TextWidth(strp3);       maxArray[0]:=t;
           maxArray[1]:=t1;
           maxArray[2]:=t2;
           maxArray[3]:=t3;
           iMax:=maxArray[0];
           for x:=0 to 3 do
               if maxArray[x]> iMax then
                   iMax:= maxArray[x];
           
           //进行排列,strp为第一列,strp1为第二列,strp2为第三列,strp3为第四列
           spacestr:='';
           if iMax>t then
           begin
              if RoundClassic((iMax-t)/3)>=1 then //空格为3
              begin
                  for j := 1 to RoundClassic((iMax-t)/3) do   //RoundClassic为四色五入
                      spacestr:=spacestr+' ';
              end;        
           end;
           strp:=strp+spacestr+'   |';
           
           spacestr:='';
           if iMax>t1 then
           begin
              if RoundClassic((iMax-t1)/3)>=1 then //空格为3
              begin
                  for j := 1 to RoundClassic((iMax-t1)/3) do   //RoundClassic为四色五入
                      spacestr:=spacestr+' ';
              end;        
           end;
           strp1:=strp1+spacestr+'   |';       spacestr:='';
           if iMax>t2 then
           begin
              if RoundClassic((iMax-t2)/3)>=1 then //空格为3
              begin
                  for j := 1 to RoundClassic((iMax-t2)/3) do   //RoundClassic为四色五入
                      spacestr:=spacestr+' ';
              end;        
           end;
           strp2:=strp2+spacestr+'   |';       spacestr:='';
           if iMax>t3 then
           begin
              if RoundClassic((iMax-t3)/3)>=1 then //空格为3
              begin
                  for j := 1 to RoundClassic((iMax-t3)/3) do   //RoundClassic为四色五入
                      spacestr:=spacestr+' ';
              end;        
           end;
           strp3:=strp3+spacestr+'   |';
    end;结果是还是不理想,问题出在哪里啊?