我有下面这个代码从4个不同的列表框打印但不打印列表框中的信息但我可以查看我需要在打印预览中打印但在打印时不显示的信息。但没有什么打印....
提前致谢。
private void btnPrint_Click(object sender, EventArgs e)
{
printDocument1.OriginAtMargins = true;
printDocument1.DocumentName = "Barcode";
printPreviewDialog1.Document = printDocument1;
string itemcode = "";
string itemDescription = "";
string inclValue = "";
string exclValue = "";
foreach (object x in lstbxItemCode.Items)
{
itemcode = itemcode + x + "\n";
}
foreach (object y in lstbxItemDesc.Items)
{
itemDescription = itemDescription + y + "\n";
}
foreach (object z in lstbxInclValue.Items)
{
inclValue = inclValue + z + "\n";
}
foreach (object y in lstbxExclValue.Items)
{
exclValue = exclValue + y + "\n";
}
myReader = new StringReader("ItemCode: " + itemcode + "\n" + "ItemDescription: " + itemDescription + "\n" + "InclValue: " +"R " + inclValue + "\n" + "ExclValue: " +"R " + exclValue);
printPreviewDialog1.Show();
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs ev)
{
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
Font printFont = lstbxItemCode.Font;
using (var myBrush = new SolidBrush(Color.Black))
{
float linesPerPage = ev.MarginBounds.Height/printFont.GetHeight(ev.Graphics);
// Iterate over the string using the StringReader, printing each line.
while (count < linesPerPage && ((line = myReader.ReadLine()) != null))
{
// calculate the next line position based on
// the height of the font according to the printing device
float yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics));
// draw the next line in the rich edit control
ev.Graphics.DrawString(line, printFont,
myBrush, leftMargin,
yPosition, new StringFormat());
count++;
}
}
}