C#系统的打印功能的实现
具体代码套用
//打印功能
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDocument printDocument1 = new PrintDocument();
//printDocument1.DefaultPageSettings.PrinterSettings.PrinterName = "ZDesigner GX430t";//打印机名称设置
//printDocument1.DefaultPageSettings.PaperSize = new ("Custum", label_biaoda1.Width, label_biaoda1.Height);//设置纸张大小
printDocument1.PrintPage += new PrintPageEventHandler(this.PrintDocument_PrintPage);
PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog();
printPreviewDialog1.Document = printDocument1;
DialogResult result = printPreviewDialog1.ShowDialog();
if (result == DialogResult.OK)
printDocument1.Print();
}
//以下代码获取到一张用作打印内容的图片
private void PrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Image image = Image.FromFile(@"D:\12140\Desktops\Picture\1.png");
Bitmap _NewBitmap = (Bitmap)image;
/* e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);//调整图片的大小
e.Graphics.DrawImage(_NewBitmap, 0, 0, 570, 380);*/
//各种调整,消除锯齿
/*e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
_NewBitmap.SetResolution(583, 390);*/
e.Graphics.DrawImage(image, 0, 0, image.Width, image.Height);
//_NewBitmap.Save("D:\\0000-临时文件\\1.png", System.Drawing.Imaging.ImageFormat.Png);//图片保存
}
这样就能够实现一个简陋一点儿的打印功能啦~~
点击打印按钮: