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

求教,关于小票打印机 打印 datagridview后终止的问题
求教各位大侠,小弟用vs2008自带的打印控件 在小票打印机上 打印winform程序中的部分内容(包含固定内容和datagridview),当使用for循环打完datagridview后,打印机停止打印,后续的固定内容 需 按住小票打印机的出纸按钮,才能打出来,尝试过增加打印末尾的长度,但只有增加300的时候都给打印了出来,但空白纸也拉出很长,增加25 50 100都是终止于for循环打完datagridview。
代码如下,跪求指导....
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
  {
  DataTable dt = (DataTable)dataGridView1.DataSource;
  int x = 10, y = 0, kuan = 50, gao = 25;
  int count = Convert.ToInt32(dataGridView1.Rows.Count.ToString());
  Font ff = new Font("宋体", 10);
  Font f2 = new Font("宋体", 12);
  x += 40;
  y += gao;
  e.Graphics.DrawString("xx超市发货单", f2, Brushes.Blue, x, y);
  y += 40;
  x -= 40;
  e.Graphics.DrawString("收货单位:", ff, Brushes.Blue, x, y);
  x += 60;
  e.Graphics.DrawString((string)comboBox1.Text.ToString(), ff, Brushes.Blue, x, y);
  y += gao;
  x -= 60;
  e.Graphics.DrawString("发货时间:", ff, Brushes.Blue, x, y);
  x += 60;
  e.Graphics.DrawString((string)DateTime.Now.ToLongDateString(), ff, Brushes.Blue, x, y);
  y += gao;
  x -= 60;
  e.Graphics.DrawString("---------------------------------", ff, Brushes.Blue, x, y);
  y += gao;
  e.Graphics.DrawString("商品名称", ff, Brushes.Blue, x, y);
  x += 32;
  x += 80;
  e.Graphics.DrawString("数量", ff, Brushes.Blue, x, y);
  x += 32;
  e.Graphics.DrawString("单位", ff, Brushes.Blue, x, y);
  x += 32;
  e.Graphics.DrawString("单价", ff, Brushes.Blue, x, y);
  x += 32;
  e.Graphics.DrawString("小计", ff, Brushes.Blue, x, y);
  x += 35;


  foreach (DataColumn column in dt.Columns)
  {
  switch (column.ColumnName)
  {
  case "商品名称DataGridViewTextBoxColumn":
  case "单价DataGridViewTextBoxColumn":

  break;
  default:
  continue;
  }
  e.Graphics.DrawString(column.ColumnName, ff, Brushes.Black, x, y);
  x += kuan;

  }
  y += gao;
  x = 10;
  for (int i = 0; i < count; i++)
  {
  dataGridView1.EndEdit();
  DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];
  Boolean flag = Convert.ToBoolean(checkCell.Value);
  if (flag == true)
  {
  for (int j = 1; j <= 5; j++)
  {

  e.Graphics.DrawString((string)dt.Rows[i].ItemArray[j].ToString(), ff, Brushes.Black, x, y);
  if (j == 1)
  {
  x += 80;
  }
  x += 32;
  }
  }
  x = 10;