Click here to Skip to main content
14,237,418 members
Rate this:
Please Sign up or sign in to vote.
Hello Guys,in my new project am facing a problem in printing receipt it's shows blank spaces not but it's now showing data of datagridview in receipt please help me and tell me please where is the problem in my code

What I have tried:

private void printreceiptCash()
        {
            PrintDialog printdialog1 = new PrintDialog();
            PrintDocument printdocument1 = new PrintDocument();
            PaperSize bp = new PaperSize("Custom", 100, 200);
            printdialog1.Document = printdocument1;
            printdocument1.PrintPage += new PrintPageEventHandler(printdocument1_PrintPage);
            printdocument1.DefaultPageSettings.PaperSize = bp;
            printdocument1.DefaultPageSettings.PaperSize.Height = 1510;
            printdocument1.DefaultPageSettings.PaperSize.Width = 320;
            printdocument1.PrinterSettings.PrinterName = setaluefortextprinter;
            //DialogResult result = printdialog23.ShowDialog();
            //if (result == DialogResult.OK)
            //{
            printdocument1.Print();
            //}
        }
        void printdocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics graphics = e.Graphics;
            Font f = new Font("Arial", 8);
            float fontHeight = f.GetHeight();
            int starto = 0;
            int startp = 20;
            int startoo = 180;
            int startpp = 9;
            int startX = 10;
            int startY = 10;
            int offset = 220;
            int offset1 = 260;
            int offset2 = 280;
            int line = 60;
            int line1 = 1;
            int line2 = 6;
            int line3 = 10;
            int line4 = 0;
            int line5 = 62;
            int line6 = 20;
            int line7 = 3;
            int line8 = 6;
            int line9 = 40;
            int linesame = 15;
            int linesame1 = 50;
            int offset3 = 290;
            int offset4 = 300;
            int offset5 = 270;
            int offset6 = 320;
            int offset7 = 350;
            int offset8 = 80;
            int offset9 = 40;
            int offset10 = 320;

            graphics.DrawString("ABC Branch", new Font("Courier New", 9), new SolidBrush(Color.Black), line2, line3);
            //graphics.DrawString(setaluefortext00001name, new Font("Courier New", 15), new SolidBrush(Color.Black), line, line1);
            graphics.DrawString("Cold Drinks", new Font("Courier New", 6), new SolidBrush(Color.Black), starto, startp);
            graphics.DrawString("All Kinds Of SoftDrinks", new Font("Courier New", 6), new SolidBrush(Color.Black), line8, line9);
            //graphics.DrawString("Order#" + label2.Text, new Font("Courier New", 6), new SolidBrush(Color.Black), linesame, linesame1);
            graphics.DrawString("Cash Memo", new Font("Courier New", 6), new SolidBrush(Color.Black), linesame, linesame1);
            graphics.DrawString("-------------------------------------------------", new Font("Courier New", 6), new SolidBrush(Color.Red), line4, line5);
            for (int z = 0; z < dataGridView1.Rows.Count; z++)
            {
                string productDescription = dataGridView1.Rows[z].Cells[0].Value.ToString();
                //string productTotal = dataGridView67.Rows[z].Cells[3].Value.ToString();
                string flaours = dataGridView1.Rows[z].Cells[3].Value.ToString();
                //string req = dataGridView1.Rows[z].Cells[8].Value.ToString();
                string productTotal1 = " Rs " + dataGridView1.Rows[z].Cells[0].Value.ToString();
                string prodcutLine = productDescription + flaours;
                graphics.DrawString(prodcutLine, new Font("Courier New", 9), 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:}", textBox2.Text), f, new SolidBrush(Color.Black), startX, startY + offset3);
            graphics.DrawString("Thank You For Choosing US,".PadRight(15) + string.Format(""), f, new SolidBrush(Color.Black), startX, startY + offset4);
Posted
Comments
CHill60 6-Dec-16 19:49pm
   
I've just read your question twice and have no idea what your problem is!
Use the Improve question link to give some sample output and explain clearly what is wrong/what is going wrong
NotPolitcallyCorrect 6-Dec-16 20:33pm
   
Start by doing what you have already been told to do and use your debugger to debug your code. Then you might be able to provide a coherent description of your problem, if you actually have one.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100