I am trying to print windows form with all controls on it as captured screen, but it prints a blank page. Where I am wrong? Here is the code i use:
private void OutputLaundry_Load(object sender, EventArgs e)
{
Out ou = new Out();
ou.Lst = Main.laundryOutList;
ou.ClientName = Main.clientOutName;
ou.Employee = Login.user.Name;
label2.Text = DateTime.Today.ToString("dd.MM.yyyy");
label3.Text = ou.ClientName;
DBC.outputLaundry(dgvOut, ou.Lst);
label4.Text = ou.Employee;
}
private void button1_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
Bitmap memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}