我在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));发布于 2020-06-02 17:27:51
这将按照您的要求“显示下一行的数量、价格和金额”:
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上适合的行数。
https://stackoverflow.com/questions/62157163
复制相似问题