procedure TForm1.Button1Click(Sender: TObject); var text: string; textsize: SIZE; spacing,i: Integer; rect: TRect; begin text:= 'lovelymelon'; {设置文本间距:(矩形宽度-文本宽度)/文本个数} SetRect(rect, 50, 50, 300, 100); Rectangle(Form1.Canvas.Handle, rect.left, rect.Top, rect.Right, rect.bottom); GetTextExtentPoint(Form1.Canvas.Handle, PChar(text), length(text), TextSize); i:=textsize.cx div Length(text);//每个字符的宽度 Spacing:= (Rect.Right-Rect.Left-TextSize.cx-i*2) div (length(text)-1);//每个字符的平均间距 SetTextCharacterExtra(form1.Canvas.Handle, Spacing);//设置字符输出的间隔 TextOut(form1.Canvas.Handle,rect.Left+i,rect.Top+(rect.Bottom-rect.Top-textsize.cy) div 2,PChar(text),Length(text));//输出字符串 end;