Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Guys, i want to set my receipt alignment my receipt alignment is to dirty and i dont know how to set standard print receipt alignment
please see my receipt alignment

[^]

What I have tried:

C#
Graphics graphics = e.Graphics;
            Font f = new Font("Arial", 8);
            float fontHeight = f.GetHeight();
            int starto = 30;
            int startp = 6;
            int startoo = 180;
            int startpp = 9;
            int startX = 10;
            int startY = 10;
            int offset = 40;
            int offset1 = 260;
            int offset2 = 280;
            int line = 1;
            int line1 = 5;
            int line2 = 6;
            int line3 = 24;
            int line4 = 124;
            int line5 = 32;
            int line6 = 20;
            int line7 = 3;
            int line8 = 6;
            int line9 = 32;
            int offset3 = 250;
            int offset4 = 260;
            int offset5 = 270;

            graphics.DrawString(txtDisplay.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), line, line1);
            graphics.DrawString(setaluefortext00001name, new Font("Courier New", 15), new SolidBrush(Color.Black), starto, startp);
            graphics.DrawString("*****************************************************************", new Font("Courier New", 6), new SolidBrush(Color.Black), line2, line3);
            graphics.DrawString(label4.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), line8, line9);
            //graphics.DrawString("Order No: "+ + label2.Text, new Font("Courier New", 6), new SolidBrush(Color.Red), line4, line5);
            foreach (tblProductEx product in products1)
            {
                //for (int z = 0; z < dataGridView2.Rows.Count - 1; z++)
                //{
                    string productDescription = product.productName.PadRight(30);

                    string productTotal = "Rs:" + string.Format("{0:}", product.productPrice);
                    string prodcutLine = productDescription + productTotal;

                    graphics.DrawString(prodcutLine, f, new SolidBrush(Color.Black), startX, startY + offset);

                    offset = offset + (int)fontHeight + 5;
                //}
            }
            offset = offset + 20;
            tblTransaction transaction = new tblTransaction();
            transaction.transactionDate = DateTime.Now;
            graphics.DrawString("Total To Pay".PadRight(15) + "Rs " + string.Format("{0:}", total1), f, new SolidBrush(Color.Black), startX, startY + offset3);
            graphics.DrawString("Thank You For Coming,".PadRight(15) + string.Format(""), f, new SolidBrush(Color.Black), startX, startY + offset4);
Posted
Updated 13-Oct-16 14:28pm

1 solution

Quote:
i dont know how to set standard print receipt alignment
You are already doing alignment, you simply do it wrong.

See what you do: each tome you draw a string, you give coordinates which tell where the left part begins.
For label aligned on left, just give coordinates.
For label aligned on right or centered, you need to query the system for the length and compute the matching left coordinate.
for centered label, the left coordinate is center coordinate minus length/2.
for right label, the left coordinate is right coordinate minus length.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900