Here is a DEMO: (I forget Why I wrote it in 1997)
procedure TForm1.Button1Click(Sender: TObject);
var
dd:array[0..100] of Char;
PHdc:Hdc;
SZ:Tsize;
RGN1,RGN:HRgn;
begin
SetWindowRgn(Handle,RgnBack,True);
Phdc:=Form1.Canvas.Handle;
StrPcopy(dd,Edit1.Text);
SelectObject(Phdc,Label1.Font.Handle);
begin
path(PHdc);
TextOut(Phdc,0,0,@dd,length(dd));
Endpath(PHdc);
GetTextExtentPoint(Phdc,dd,length(dd),SZ);
RGN:=CreateRectRgn(0,0,SZ.Cx,SZ.Cy);
RGN1:=PathToRegion(Phdc);
CombineRgn(RGN,RGN,RGN1,RGN_Xor);
SetWindowRgn(handle,RGN,true);
form1.Clientwidth:=SZ.Cx;
Form1.ClientHeight:=SZ.CY;
end;