我正在尝试打印带有所有控件的窗体作为捕获屏幕,但它会打印一个空白页面。哪里错了?这是我使用的代码:
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);
}