我是在printDocument1_PrintPage事件里
用e.Graphics.DrawString来打印字符串
form中设置一个按钮,单击按钮的时候
   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

解决方案 »

  1.   

    winform项目中读取本地打印机列表
    C#调用局域网中POS打印机
    WEB免费打印控件推荐
      

  2.   

    哥们,我刚才试了一下 你用微软自带的打印机调试下,有啥不明白你再回帖吧 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));
            }
      

  3.   

    LZ加我Q453367672我有demo,源码献上