
Zitat von
Luckie:
Ich dachte so geht es, aber in der for-Zeile meint er, inkompatible Typen.
Na ja, ich tippe einfach mal, das liegt daran, dass du "Length" auf einen PInteger anwenden willst, oder?
//Edit:
Hilft dir das hier? Hab' ich bei Experts Exchange gefunden, müsstest natürlich noch etwas anpassen.
Delphi-Quellcode:
procedure TForm1.but_CustomTextClick(Sender: TObject);
var
TextStr:
String;
Bmp1: TBitmap;
numChar, oNum, lines: Integer;
aSize: tagSize;
begin
TextStr := '
Thisisatextstringlongenoughtowrap a couple of times. And'+
'
Moretextherefollowedbevenmore text followed by eveen more text'+
'
followed-by-even-more-text followed by even moore text';
Bmp1 := TBitmap.Create;
try
Bmp1.Width := 188;
// try to have a 3 pixel border, use 182 below
Bmp1.Height := 230;
Bmp1.Canvas.Font.
Name := '
Arial';
Bmp1.Canvas.Font.Size := 11;
if Length(TextStr) < 1
then Exit;
lines := 0;
repeat
GetTextExtentExPoint(Bmp1.Canvas.Handle, PChar(TextStr),Length(TextStr),182,
@numChar,
nil, aSize);
oNum := numChar;
while (numChar > 1)
and not
(TextStr[numChar]
in ['
','
.','
,','
-','
_','
?','
!','
$','
(','
)'])
do
Dec(numChar);
if numChar = 1
then
numChar := oNum;
TextOut(Bmp1.canvas.handle,3,(lines*(aSize.cy+8))+3,PChar(TextStr), numChar);
Delete(TextStr,1,numChar);
Inc(Lines);
until Length(TextStr) < 1;
Canvas.Draw(530,290, Bmp1);
finally
FreeAndNil(Bmp1);
end;
end;
Quelle