winform打印
private void printForm()
{
img = new Bitmap(panel1.Width, panel1.Height);
Size s = new Size();
s.Width = panel1.Width;
s.Height = panel1.Height;
Graphics g = Graphics.FromImage(img);
g.CopyFromScreen(this.Location.X + 6, this.Location.Y +133, 0, 0, s);
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(this.img, new Rectangle(80, 50, panel1.Width,panel1.Height));
}
private void btnPrint_Click(object sender, EventArgs e)
{
try
{
printForm();
this.printPreviewDialog1.Document = this.printDocument1;
this.printPreviewDialog1.ShowDialog(this);
printDocument1.Print();
}
catch
{
MessageBox.Show("请检查您的打印机是否连接正常!");
return;
}
}