收据在打印文档中有重叠文本
Receipt has overlapping text in Print Document
我正在我的 POS 项目中创建打印收据并附上输出图片
我的问题是描述、数量、价格、金额重叠。
如何在此代码的下一行显示数量、价格和金额?
e.Graphics.DrawString("Description" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, 260));
e.Graphics.DrawString("Qty" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(120, 260));
//e.Graphics.DrawString("UM" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(190, 190));
e.Graphics.DrawString("Price", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(155, 260));
e.Graphics.DrawString("Amount" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(205, 260));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, 275));
int yPos = 300;
foreach (var i in TempVal)
{
e.Graphics.DrawString(i.Particular + " (" + i.UM + ")", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos));
e.Graphics.DrawString(i.Qty, new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(120, yPos));
//e.Graphics.DrawString(i.UM, new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(190, yPos));
e.Graphics.DrawString(i.Price +".00", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(155, yPos));
e.Graphics.DrawString(i.Total + ".00", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(205, yPos));
yPos = yPos + 20;
}
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos));
e.Graphics.DrawString("Total Amount: Php " + label3.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos+20));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos+35));
e.Graphics.DrawString("Cash Tendered: Php " + label4.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos + 55));
e.Graphics.DrawString("Change: Php " + lblTotal.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos + 75));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos+95));
这将按照您的要求“在下一行显示数量、价格和金额”:
using (var f = new Font("trebuchet ms", 10, FontStyle.Regular))
{
int yPos = 300;
foreach (var v in TempVal)
{
e.Graphics.DrawString(v.Particular + " (" + v.UM + ")", f, Brushes.Black, new Point(0, yPos));
yPos += 20;
e.Graphics.DrawString(v.Qty, f, Brushes.Black, new Point(120, yPos));
e.Graphics.DrawString(v.Price +".00", f, Brushes.Black, new Point(155, yPos));
e.Graphics.DrawString(v.Total + ".00", f, Brushes.Black, new Point(205, yPos));
yPos += 20;
}
}
请注意,这仅在 TempVal
保证只有很少的记录以至于它们都可以放在一页上时才有效。如果有足够的记录需要更多的页面,您将必须计算一页可以容纳多少行和 split your output onto multiple pages.
我正在我的 POS 项目中创建打印收据并附上输出图片
我的问题是描述、数量、价格、金额重叠。 如何在此代码的下一行显示数量、价格和金额?
e.Graphics.DrawString("Description" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, 260));
e.Graphics.DrawString("Qty" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(120, 260));
//e.Graphics.DrawString("UM" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(190, 190));
e.Graphics.DrawString("Price", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(155, 260));
e.Graphics.DrawString("Amount" , new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(205, 260));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, 275));
int yPos = 300;
foreach (var i in TempVal)
{
e.Graphics.DrawString(i.Particular + " (" + i.UM + ")", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos));
e.Graphics.DrawString(i.Qty, new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(120, yPos));
//e.Graphics.DrawString(i.UM, new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(190, yPos));
e.Graphics.DrawString(i.Price +".00", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(155, yPos));
e.Graphics.DrawString(i.Total + ".00", new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(205, yPos));
yPos = yPos + 20;
}
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos));
e.Graphics.DrawString("Total Amount: Php " + label3.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos+20));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos+35));
e.Graphics.DrawString("Cash Tendered: Php " + label4.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos + 55));
e.Graphics.DrawString("Change: Php " + lblTotal.Text.Trim(), new Font("trebuchet ms", 10, FontStyle.Regular), Brushes.Black, new Point(0, yPos + 75));
e.Graphics.DrawString("-------------------------------------------", new Font("trebuchet ms", 12, FontStyle.Regular), Brushes.Black, new Point(0, yPos+95));
这将按照您的要求“在下一行显示数量、价格和金额”:
using (var f = new Font("trebuchet ms", 10, FontStyle.Regular))
{
int yPos = 300;
foreach (var v in TempVal)
{
e.Graphics.DrawString(v.Particular + " (" + v.UM + ")", f, Brushes.Black, new Point(0, yPos));
yPos += 20;
e.Graphics.DrawString(v.Qty, f, Brushes.Black, new Point(120, yPos));
e.Graphics.DrawString(v.Price +".00", f, Brushes.Black, new Point(155, yPos));
e.Graphics.DrawString(v.Total + ".00", f, Brushes.Black, new Point(205, yPos));
yPos += 20;
}
}
请注意,这仅在 TempVal
保证只有很少的记录以至于它们都可以放在一页上时才有效。如果有足够的记录需要更多的页面,您将必须计算一页可以容纳多少行和 split your output onto multiple pages.