我想打印列表视图。 我希望它在我打印时转到下一行。 (它停留在同一条线上并写入(===) 如果可以,请提交代码 请! [但这是我将其打印到XPS文档1
时的输出 {
this.Hide();
try
{
PrintDialog printDialog = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
printDialog.Document = printDocument;
printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(CreateReceipt);
DialogResult result = printDialog.ShowDialog();
if (result == DialogResult.OK)
{
printDocument.Print();
}
if (result == DialogResult.Cancel)
{
Form2 fr2 = new Form2();
fr2.Show();
}
}
catch
{
MessageBox.Show("Error, Occured While Printing");
Form2 fr2 = new Form2();
fr2.Show();
}
this.Show();
}
public void CreateReceipt(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics graphic = e.Graphics;
Font font = new Font("Courier New", 12);
float fontHeight = font.GetHeight();
int startX = 10;
int startY = 10;
int offset = 40;
offset = offset + (int)fontHeight;
{
graphic.DrawString("Bill Flow", new Font("Courier New", 18), new SolidBrush(Color.Black), startX, startY);
string top = "Item Name".PadRight(15) + "Price".PadRight(12) + "Quantity";
graphic.DrawString(top, font, new SolidBrush(Color.Black), startX, startY + offset);
offset = offset + (int)fontHeight;
graphic.DrawString("-----------------------------------------------", font, new SolidBrush(Color.Black), startX, startY + offset);
}
{
StringBuilder listViewContent = new StringBuilder();
listViewContent.ToString();
//THIS IS THE PART WHERE ITS WRONG I GUESS
{
for (int item = 0; item < this.listView1.Items.Count; item++)
{
for (int subitem = 0;
subitem < this.listView1.Columns.Count;
subitem++)
{
listViewContent.Append
(this.listView1.Items[item].SubItems[subitem].Text);
if (subitem < this.listView1.Columns.Count - 1)
listViewContent.Append(" ");
}
string ln;
ln = listViewContent.ToString();
graphic.DrawString(ln+"\n", new Font("Courier New", 12, FontStyle.Italic), new SolidBrush(Color.Red), startX, startY + offset);
this.Show();
}
}
}
}