Reputation: 407
there are two forms in my program, Form A
and Form B
.
There is a button in Form A
which can take a screen shot of Form B
(without start Form B
).
However, the components of Form B
are created in Form_Load
function.
I use the below code to take a screen shot of Form B
but it only generate a empty Form B
image without any component of its.
Bitmap b = new Bitmap(1280, 720);
formB.ManualLoad();
formB.DrawToBitmap(b, new Rectangle(0, 0, 1280, 720));
b.Save("D:\\Test.bmp");
The Manuaload() function is in below.
public void ManualLoad()
{
formB_Load(null, null);
formB_Resize(null, null);
Invalidate();
}
How can I fix the problem?
Upvotes: 0
Views: 249
Reputation: 81
I think
formB_Load(null, null); and formB_Resize(null, null);
ints even hanler load and resize event's
next code will be to work
Bitmap b = new Bitmap(1280, 720);
var form = new formB();
form.Visible = false;
form.Show();
form.DrawToBitmap(b, new Rectangle(0, 0, 1280, 720));
form.Close();
b.Save("D:\\Test.bmp");
Upvotes: 3