locked
Print paper setings RRS feed

  • Question

  • i develop a windows application in c# and want a print section its working but the problem is i want only a bill paper now print come in a A4 size paper. How i adjust the width and height of the print paper. I paste my code below pls help me.

    private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
            {
                int y, x, i;
                // Print receipt
                y = e.MarginBounds.Y;
                x = e.MarginBounds.X;
           
                i = x;
                Font myFont = new Font("Arial", 16, FontStyle.Bold);

                e.Graphics.DrawString("G SAND", myFont, Brushes.Black, (e.MarginBounds.Width / 2) / 2, y);
                e.Graphics.DrawString("G SAND", myFont, Brushes.Black, (e.MarginBounds.Width / 2) + (e.MarginBounds.Width / 2) / 2, y);
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                myFont = new Font("Arial", 10, FontStyle.Regular);
                e.Graphics.DrawString("GATE PASS", myFont, Brushes.Black, (e.MarginBounds.Width / 2) / 2, y);
                e.Graphics.DrawString("LOADING PASS", myFont, Brushes.Black, (e.MarginBounds.Width / 2) + (e.MarginBounds.Width / 2) / 2, y);
                y += Convert.ToInt32(2 * myFont.GetHeight(e.Graphics));
                e.Graphics.DrawString("Pass No." + bill.ToString(), myFont, Brushes.Black, 50, y);
                e.Graphics.DrawString("Pass No." + bill.ToString(), myFont, Brushes.Black, (e.MarginBounds.Width / 2) + 40, y);
                y += Convert.ToInt32(2 * myFont.GetHeight(e.Graphics));
                e.Graphics.DrawString("Date." + DateTime.Now.ToString(), myFont, Brushes.Black, 50, y);
                e.Graphics.DrawString("Date." + DateTime.Now.ToString(), myFont, Brushes.Black, ((e.MarginBounds.Width / 2) + 40), y);
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                e.Graphics.DrawString("Vechicle " + txt_reg.Text, myFont, Brushes.Black, 50, y);
                e.Graphics.DrawString("Vechicle " + txt_reg.Text, myFont, Brushes.Black, ((e.MarginBounds.Width / 2) + 40), y);
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                e.Graphics.DrawString("Capacity " + txt_cap.Text + "+" + txt_ext.Text + "=" + txt_max.Text, myFont, Brushes.Black, 50, y);
                e.Graphics.DrawString("Capacity " + txt_cap.Text+"+"+txt_ext.Text+"="+txt_max.Text, myFont, Brushes.Black, ((e.MarginBounds.Width / 2) + 40), y);
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                for (int j = 50; j < e.MarginBounds.Width / 2; j++)
                {
                    e.Graphics.DrawString("-", myFont, Brushes.Black, j, y);
                }
                for (int k = e.MarginBounds.Width / 2 + 40; k < e.MarginBounds.Width; k++)
                {
                    e.Graphics.DrawString("-", myFont, Brushes.Black, k, y);

                }
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                e.Graphics.DrawString("Item", myFont, Brushes.Black, 50, y);
                e.Graphics.DrawString("Item", myFont, Brushes.Black, (e.MarginBounds.Width / 2) + 40, y);
                e.Graphics.DrawString("Rate", myFont, Brushes.Black, 130, y);
                e.Graphics.DrawString("Rate", myFont, Brushes.Black, (e.MarginBounds.Width / 2) + 130, y);
                e.Graphics.DrawString("Qty", myFont, Brushes.Black, e.MarginBounds.Width / 2 - 150, y);
                e.Graphics.DrawString("Qty", myFont, Brushes.Black, e.MarginBounds.Width - 150, y);
                e.Graphics.DrawString("Price", myFont, Brushes.Black, e.MarginBounds.Width/2 - 50, y);
                e.Graphics.DrawString("Price", myFont, Brushes.Black, e.MarginBounds.Width - 50, y);
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                for (int k = 50; k < e.MarginBounds.Width / 2; k++)
                {
                    e.Graphics.DrawString("-", myFont, Brushes.Black, k, y);

                }
                for (int k = e.MarginBounds.Width / 2 + 40; k < e.MarginBounds.Width; k++)
                {
                    e.Graphics.DrawString("-", myFont, Brushes.Black, k, y);

                }
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(comboBox1.SelectedItem.ToString(), myFont, Brushes.Black,50, y);
                e.Graphics.DrawString(comboBox1.SelectedItem.ToString(), myFont, Brushes.Black, (e.MarginBounds.Width / 2) + 40, y);
                e.Graphics.DrawString(txt_rate.Text, myFont, Brushes.Black, 130, y);
                e.Graphics.DrawString(txt_rate.Text, myFont, Brushes.Black, (e.MarginBounds.Width / 2) + 130, y);
                e.Graphics.DrawString(txt_max.Text, myFont, Brushes.Black, e.MarginBounds.Width / 2 - 150, y);
                e.Graphics.DrawString(txt_max.Text, myFont, Brushes.Black, e.MarginBounds.Width - 150, y);
                e.Graphics.DrawString(txt_gtot.Text, myFont, Brushes.Black, e.MarginBounds.Width / 2 - 50, y);
                e.Graphics.DrawString(txt_gtot.Text, myFont, Brushes.Black, e.MarginBounds.Width - 50, y);
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));

                for (int k =50; k < e.MarginBounds.Width / 2; k++)
                {
                    e.Graphics.DrawString("-", myFont, Brushes.Black, k, y);
                }
                for (int k = e.MarginBounds.Width / 2 + 40; k < e.MarginBounds.Width; k++)
                {
                    e.Graphics.DrawString("-", myFont, Brushes.Black, k, y);

                }
                y += Convert.ToInt32(myFont.GetHeight(e.Graphics));

                myFont = new Font("Arial", 12, FontStyle.Bold);
                e.Graphics.DrawString("TOTAL QTY " + txt_max.Text + "   TOTAL " + txt_gtot.Text, myFont, Brushes.Black, 50, y);
                e.Graphics.DrawString("TOTAL QTY " + txt_max.Text + "   TOTAL " + txt_gtot.Text, myFont, Brushes.Black, (e.MarginBounds.Width / 2) + 40, y);
                //printDocument.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("PaperA4", 840, 1180);
              
                e.HasMorePages = false;
            }

    • Moved by Lie You Wednesday, March 28, 2012 2:31 AM Move it for better support. (From:.NET Base Class Library)
    Tuesday, March 27, 2012 5:55 AM

Answers

All replies