首页新闻找找看学习计划

谁会打印机程序呀

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

我写了一个打印机程序,可是,一点击打印的时候,第一页打印完,它打了两个空页才打印第二页,这是怎么回事, 我的代码如下:

  

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Printing;

using Cstool;

using JohnsonI.BLL;

using JohnsonI.Model;

namespace Print_EPSON {   

  public partial class Print : Form    

{        

private T_PLAN_AUTO _model_plan_auto = new T_PLAN_AUTO();        

private BLL_PLAN_AUTO _bll_plan_auto = new BLL_PLAN_AUTO();

        private int _count = 0;

        public Print()        

    {

            InitializeComponent();

        }

        private void SetValue()

        {

            DataSet ds = new DataSet();

            ds = _bll_plan_auto.EPSON_GET_CONFIG();                 dataGridView1.DataSource = ds.Tables[0];

            dataGridView1.Columns[3].Width = 150;             dataGridView1.Columns[4].Width = 150;

            dataGridView1.Columns[5].Width = 150;

        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)         {         

            Font font;

            string str;

            float xPos;       //x点坐标

            float yPos;       //y点的坐标

            float topMargin = 40;

            float leftMargin = 10;

            DataSet ds = new DataSet();

            ds = _bll_plan_auto.EPSON_GET_CONFIG();

            for (int i = _count+1; i <= ds.Tables[0].Rows.Count; i++)

            {

                font = new Font("宋体", 12);

                str = ds.Tables[0].Rows[i-1][0].ToString();

                xPos = leftMargin + 15;

                yPos = topMargin * i + 30;

                e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

                font = new Font("宋体", 12);

                str = ds.Tables[0].Rows[i-1][1].ToString();

                xPos = leftMargin + 70;

                yPos = topMargin * i + 30;

                e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

                font = new Font("宋体", 12);

                str = ds.Tables[0].Rows[i-1][2].ToString();

                xPos = leftMargin + 125;

                yPos = topMargin * i + 30;

                e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

                font = new Font("宋体", 12);

                str = ds.Tables[0].Rows[i-1][3].ToString();

                xPos = leftMargin + 195;

                yPos = topMargin * i + 30;

                e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

                font = new Font("宋体", 12);

                str = ds.Tables[0].Rows[i - 1][4].ToString();

                xPos = leftMargin + 365;

                yPos = topMargin * i + 30;

                e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

                font = new Font("宋体", 12);

                str = ds.Tables[0].Rows[i - 1][5].ToString();

                xPos = leftMargin + 515;

                yPos = topMargin * i + 30;

                e.Graphics.DrawString(str, font, Brushes.Black, xPos, yPos, new StringFormat());

                _count = _count + 1;

                //if(_count==10)

                if (_count % 10==0)

                {

                    //WritePrinter(PrinterHandle,Pinter('#12'),Len('#12'));                     e.HasMorePages = true;

                    break;

                }

                else if (_count == ds.Tables[0].Rows.Count)     

            {

                    e.HasMorePages = false;

                    _count = 0;

                    return;

                }

            }

        }

 

     public void print_content(string str_Printer, short sho_printNum)          {

            try

            {

                PrintDocument pd = new PrintDocument();    

             pd.PrinterSettings.PrinterName = str_Printer;   

              pd.PrinterSettings.Copies = sho_printNum;   

              pd.PrintController = new StandardPrintController();

                pd.PrintPage += new PrintPageEventHandler

(printDocument1_PrintPage);

                if (pd.PrinterSettings.IsValid)

                {

                    pd.Print();

                }

                else

                {

                    MessageBox.Show("打印机连接错误", "错误",

MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

            }

            catch (Exception e)

            {

                MessageBox.Show(e.Message);

            }

        }

        private void button1_Click(object sender, EventArgs e)

        {

            print_content("EPSON LQ-630K ESC/P2",1);

        }

        private void Print_Load(object sender, EventArgs e)

        {

            SetValue();

        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)

        {

            try

            {

                e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, new SolidBrush(Color.CadetBlue), e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);

            }

            catch (Exception ex)

            {

                MessageBox.Show("添加行号时发生错误,错误信息:" + ex.Message, "操作失败");

            }

        }

    }

}

王俊成的主页 王俊成 | 初学一级 | 园豆:162
提问于:2013-03-23 14:11
< >
分享
所有回答(1)
0

你看看打印设置里的宽度或高度太小

丶夏之星 | 园豆:5 (初学一级) | 2013-03-26 17:08

都设置好了,我在想,怎样用程序在设置一下!我今天问售后,他说在程序里也得控制一下

支持(0) 反对(0) 王俊成 | 园豆:162 (初学一级) | 2013-03-26 18:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册