以下のコードは、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++;
}
}
}