Reputation:
Hi I'm trying to print a bill for a certain transaction and i've done it but the subtotal is printing over the total line... your help is appreciated. My Code below
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);
Upvotes: 2
Views: 463
Reputation: 12683
The line graphics.DrawString("SubTotal : ".PadRight(40) + subtotal.Text, font, new SolidBrush(Color.Black), startX, startY);
is set (via startY
) to write at the same y co-ordinate as the previous line.
Best to increment the startY by the font height. Something like:
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);
This increments the startY
by the font.Height
amount which by MSDN is
Gets the line spacing of this font.
Remarks:
The line spacing is the vertical distance between the base lines of two consecutive lines of text. Thus, the line spacing includes the blank space between lines along with the height of the character itself.
Upvotes: 1