I need to dynamically draw created control to bitmap.
But it does not work, it does not draw anything.
procedure TForm2.Button1Click(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;
cb:= TCheckBox.Create(nil);
try
cb.IsChecked:= true;
cb.Repaint;
BMP:= cb.MakeScreenshot;
BMP.SaveToFile('C:\bmp.bmp');
finally
FreeAndNil(cb);
FreeAndNil(BMP);
end;
end;
I have tried also directly PaintTo - but the same effect. I have tried also setting parent but this is still not enough.
If i do same for control placed by hand on the form it is working, but dynamically created not.
How to do this. This control should not be visible anywhere i need to paint it only and free it.