日期:2014-05-18  浏览次数:21453 次

C# 自定义打印纸张大小
我是在printDocument1_PrintPage事件里
用e.Graphics.DrawString来打印字符串
form中设置一个按钮,单击按钮的时候
C# code
   PrintDialog printDialog = new PrintDialog();
            printDialog.Document = this.printDocument1;
            printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Default", 315, 394);
            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    printDocument1.Print();
                }
                catch (Exception excep)
                {
                    MessageBox.Show(excep.Message, "打印出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

我应该在添加什么代码使之可以按照8cm*10cm的尺寸打印?
谢谢了。
我自己找了“printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Default", 315, 394);”这一句代码,但是使用无效,操作系统为win XP or 2003

------解决方案--------------------
哥们,我刚才试了一下 你用微软自带的打印机调试下,有啥不明白你再回帖吧
C# code

 private void button1_Click(object sender, EventArgs e)
        {
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    printDocument1.PrintPage +=new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
                    printDocument1.DefaultPageSettings.PaperSize = new PaperSize("Default", 200, 150);
                    printDocument1.Print();
                }
                finally
                { }
            }
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs ev)
        {
            ev.Graphics.DrawString("haha", new Font("宋体", 10), Brushes.Black, new PointF(10, 10));
        }

------解决方案--------------------
LZ加我Q453367672

我有demo,源码献上