首页 新闻 会员 周边

C# PrintDocument打印问题

0
悬赏园豆:30 [待解决问题]

 不知为什么在调用 pd.Print()时报错 未处理Win32Exception,ex 操作成功完成。 说明pd.PrintPage事件添加成功并不为空,但没走printDocument_PrintPage方法
private void Printr()

{        

    PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
            try
            {
                pd.Print();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

  }

 

        private void printDocument_PrintPage(object sender, PrintPageEventArgs ev)
        {

            Font titleFont = new Font("宋体", 9, FontStyle.Bold);//标题字体           

            Font fntTxt = new Font("宋体", 9, FontStyle.Regular);//正文文字           

            Brush brush = new SolidBrush(Color.Black);//画刷           

            Pen pen = new Pen(Color.Black);           //线条颜色           

            Point po = new Point(10, 10);

            try
            {

                ev.Graphics.DrawString("DrawString方式进行打印", titleFont, brush, po);   //DrawString方式进行打印。        

            }

            catch (Exception ex)
            {

                MessageBox.Show(this, "打印出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

the shades的主页 the shades | 初学一级 | 园豆:174
提问于:2012-03-27 11:37
< >
分享
所有回答(1)
-2

pd.Print(); 没有安装打印机驱动,

但可以

PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pd;
ppd.ShowDialog();

实现预览效果

the shades | 园豆:174 (初学一级) | 2012-03-27 12:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册