0

I have written an application in C# but need help with formatting/ alignment. The code is shortened so as to focus on the problem. I'm printing transactions to a receipt printer but need to right align the net amounts.

Example
Item Amt Cost Net Amt
USD 30 66.50 1995.00
USD 1400 66.80 93520.00

PrintDocument pd = new PrintDocument();
pd.Print();

private void PrintPageEvent( object sender, PrintPageEventArgs ev)
{
float topMargin = ev.PageBounds.Top;
float leftMargin = ev.PageBounds.Left;

// where transaction is a string as indicated above
string trans = String.Format("{0}\t{1}\t{2:F2}\t{3:N}", item, Amt, Cost, NetAmt);
Graphics g = ev.Graphics;
g.DrawString(trans, printFont, Brushes.Black, leftMargin, ...);
}

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by zmariow
0

Why don't you use a monospaced font (for example Courier) and then write a small function that will pad your string with spaces on its left so that it becomes right aligned...

I always do this when writing applications that need to print on receipt printers.

Let me know if you need more clarifications.
Cheers :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.