23-06-2020, Saat: 13:16
Bunu bir procedure ile yazarsanız OnPaint olayında kendiliğinden olur. Form constrains ile sınırlayarak belli bir orandan daha küçük hale getirmeyi zaten engelleyebilirsiniz.
Örneğin :

Örneğin :

procedure TForm1.ChangeLineSpaces;
var
aWidth, aHeight, aLineHeight : Integer;
aSplit : TStringList;
i : Integer;
aBitmap : TBitmap;
aBitmapRect : TRectF;
aFormRect : TRectF;
x,y : Integer;
aBitmapData : TBitmapData;
begin
Label1.WordWrap := True;
Label1.AutoSize := True;
Label1.Text := 'DelphiCan'+ #13 + 'Delphi'+ #13 + 'Forum';
aWidth := Trunc( Label1.Canvas.TextWidth(Label1.Text) );
aHeight := Trunc( Label1.Canvas.TextHeight(Label1.Text) );
aBitmap := TBitmap.Create;
aSplit := TStringList.Create;
try
aSplit.Delimiter := #13;
aSplit.StrictDelimiter := True;
aSplit.DelimitedText := Label1.Text;
aBitmap.SetSize(1, 1); // just for measurement...
aBitmap.Canvas.Font.SetSettings( Label1.Font.Family, Label1.Font.Size, Label1.Font.StyleExt );
aLineHeight := Trunc( aBitmap.Canvas.TextHeight('H') + SpinBox1.Value );
// Set real size...
aBitmap.SetSize( Trunc(Label1.Width), Trunc(aLineHeight * (aSplit.Count+2)));
aBitmap.Canvas.BeginScene;
aBitmap.Canvas.Clear( self.Fill.Color );
aBitmap.Canvas.Fill.Color := TAlphaColors.Black;
aBitmap.Canvas.Font.SetSettings( Label1.Font.Family, Label1.Font.Size, Label1.Font.StyleExt );
aBitmap.Canvas.EndScene;
aBitmapRect := TRectF.Create(0, 0, aBitmap.Width, aBitmap.Height);
for i := 0 to pred(aSplit.Count) do begin
aBitmap.Canvas.BeginScene;
if i > 0
then aBitmapRect.Top := aBitmapRect.Top + aLineHeight
else aBitmapRect.Top := 0;
aBitmapRect.Bottom := aBitmapRect.Bottom + aLineHeight;
aBitmap.Canvas.FillText( aBitmapRect, aSplit[i], false, 1, [], TTextAlign.Leading, TTextAlign.Leading );
aBitmap.Canvas.EndScene;
end;
Self.Canvas.BeginScene;
x := Trunc(Label1.Position.X);
y := Trunc(Label1.Position.Y)+ 100;
aBitmapRect := TRectF.Create(0, 0, aBitmap.Width, aBitmap.Height);
aFormRect := TRectF.Create(x, y, aBitmap.Width+x+5, aBitmap.Height+y+5);
Self.Canvas.Fill.Color := self.Fill.Color;
Self.Canvas.FillRect( aFormRect, 1 );
aFormRect := TRectF.Create(x, y, aBitmap.Width+x, aBitmap.Height+y);
Self.Canvas.DrawBitmap( aBitmap, aBitmapRect , aFormRect, 1 );
Self.Canvas.EndScene;
finally
aSplit.Free;
aBitmap.Free;
end;
end;
procedure TForm1.SpinBox1Change(Sender: TObject);
begin
ChangeLineSpaces();
end;