C# 打印功能

private void pd_PrintPage(object sender, PrintPageEventArgs e)        

{            

  e.Graphics.DrawString("大家好", new Font("宋体", 10), new SolidBrush(System.Drawing.Color.Black), new PointF(10, 10));

                Image image = Image.FromFile(@"D:\Chrysanthemum.jpg");
                e.Graphics.DrawImage(image, new PointF(20, 20));

}        

private void button3_Click(object sender, EventArgs e)        

{            

PrintDocument pd = new PrintDocument();       

//获取打印机 默认第一个     

pd.PrinterSettings.PrinterName = PrinterSettings.InstalledPrinters[0];            

pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);            

pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);            

//打印预览            

PrintPreviewDialog ppd = new PrintPreviewDialog();            

ppd.Document = pd;            

ppd.ShowDialog();            

//打印机打印            

//pd.Print();        

}

posted on 2013-12-25 16:16  习惯简单  阅读(540)  评论(0编辑  收藏  举报

导航