解决方案 »
- Forms1:=nil 变量表示
- Invalid compiler directive: 'VARPROPSETTER'的错误信息
- 如何提高该报表(fastReport)的生成速度,在线等!
- 大家有用Delphi编写过消息队列、文件池、消息池方面的经验吗?介绍一下吧。。。
- FastReport运行期自定义报表的问题?
- 800里加急(mscomm串口通信!)
- 如何让窗体在运行时,位于屏幕的左上角?
- 简单问题,但我不知道!200分给第一个给出准确答案的人。桌面上的IE图标被删,如何将它恢复出来?
- StringGrid控件的单元格中数据加软回车的解决方法
- 搞了一年,还没解决?
- 如何PrintScreen才能把鼠标光标一起打印或放到剪切板?
- TObject中的Destroy为什么声明为虚拟方法
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;
谢谢xiaojun5556,列是对齐了,但出现的问题是有的字符显示不正常,有的字变成了□。
编辑文字哪儿不方便了
编辑文字哪儿不方便了TStringGrid不适用目前的项目,除非TStringGrid可以拆分单元格差不多。
1、把RichEdit1.Lines.Text按行储存到数组str1里面
2、通过比较,找出每一列的最长,储存到str2里面。
3、把数组str1里面的字符排版(比如说去掉空格,每个单词之间加上‘-’),每一组词的长度,按照str2里 面的长度设置。
4、按行,把str1数据赋值给RichEdit1
这样应该就应该达到LZ要求了吧
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;结果是还是不理想,问题出在哪里啊?