0
我在使用c#打印多个页面时遇到问题。我尝试了所有可能性,但尚未修复。我的问题是,我想每页打印1行,但它不这样做。目前它只在所有页面上打印第一行。 。下面是代码 在PrintPageEvent导出到打印不起作用在我的页面
for (int i = 0; i < dt.Rows.Count; i++)
{
string cell = dt.Rows[i][0].ToString();
// string itemx = dr["item_id"].ToString().PadLeft(6,'0');
string itemx = cell.PadLeft(6, '0');
string item2 = "*" + itemx + "*";
string item3 = "*UMS" + itemx + "*";
e.Graphics.DrawString(itemx, new Font("Free 3 of 9", 30, FontStyle.Regular), Brushes.Black, xValue, yValue);
e.Graphics.DrawString(item3, new Font("Courier New", 14, FontStyle.Regular), Brushes.Black, xValue, yValue2);
// yValue = yValue + 70;
// yValue2 = yValue2 + 70;
if (totalnumberA < dt.Rows.Count)
{
e.HasMorePages = true;
totalnumberA++; //return;
//eturn;
}
else
{
e.HasMorePages = false;
//totalnumberA++; //return;
}
}
和我的按钮事件是这样的
try
{
DBConnection DB = new DBConnection();
DB.cnTransact.Open();
string sql = "select * from tbl_items where serialNo='122'";
cm = new SqlCommand(sql, DB.cnTransact);
SqlDataAdapter people = new SqlDataAdapter(cm);
people.Fill(dt);
//foreach (DataRow dr in dt.Rows)
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
totalnumberA = 0;
PrintDialog dialog = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
dialog.Document = printDocument;
printDocument.DefaultPageSettings.PaperSize = paperSize;
dialog.ShowDialog();
printDocument.PrintPage += PrintDocumentOnPrintPage;
printDocument.DocumentName = "Barcodes";
printDocument.Print(); - See more at: