用c#打印收据

本文关键字:打印 | 更新日期: 2023-09-27 18:01:59

你好,我正试图打印某笔交易的账单,我已经完成了,但是小计在总行上打印…谢谢你的帮助。

下面的代码
    offset = offset + 20;
        graphics.DrawString("Total : ".PadRight(40) + total.Text, font, new SolidBrush(Color.Black), startX, startY);
        graphics.DrawString("SubTotal : ".PadRight(40) + subtotal.Text, font, new SolidBrush(Color.Black), startX, startY);

用c#打印收据

graphics.DrawString("SubTotal : ".PadRight(40) + subtotal.Text, font, new SolidBrush(Color.Black), startX, startY);行(通过startY)设置为与前一行书写在相同的y坐标上。

最好以字体高度增加起始值。比如:

offset = offset + 20;
graphics.DrawString("Total : ".PadRight(40) + total.Text, font, new SolidBrush(Color.Black), startX, startY);
startY += font.Height;
graphics.DrawString("SubTotal : ".PadRight(40) + subtotal.Text, font, new SolidBrush(Color.Black), startX, startY);

这使startY增加了font.Height的量,而MSDN是

获取该字体的行间距。

备注:

行距是指两行连续文本的基线之间的垂直距离。因此,行距包括行间的空白空间以及字符本身的高度。