private void Form7_Load(object sender, EventArgs e)
        {
            try
            {
                this.label15.Text = a.textBox3.Text + " Rs";
                label32.Text = label15.Text;
                this.label18.Text = a.textBox7.Text + " %";
                label26.Text = label18.Text;
                this.label4.Text = a.textBox6.Text + " Rs";
                label24.Text = label4.Text;
                this.label17.Text = a.textBox4.Text + " %";
                label28.Text = label17.Text;
                this.label16.Text = a.textBox5.Text + " %";
                label30.Text = label16.Text;
                this.label14.Text = a.textBox10.Text;
                label33.Text = label14.Text;
                label38.Text = a.label25.Text;
                label39.Text = label38.Text;
                Label[] lbSno = new Label[14];
                Label[] lbItm = new Label[14];
                Label[] lbQty = new Label[14];
                Label[] lbTot = new Label[14];
                Label[] lbSno1 = new Label[14];
                Label[] lbItm1 = new Label[14];
                Label[] lbQty1 = new Label[14];
                Label[] lbTot1 = new Label[14];



                for (int i = 0; i < a.dataGridView4.RowCount; i++)
                {
                    if (i < 14)
                    {
                        lbSno[i] = new Label();
                        lbItm[i] = new Label();
                        lbQty[i] = new Label();
                        lbTot[i] = new Label();
                        lbSno1[i] = new Label();
                        lbItm1[i] = new Label();
                        lbQty1[i] = new Label();
                        lbTot1[i] = new Label();

                        lbSno[i].AutoSize = true;
                        lbItm[i].AutoSize = true;
                        lbQty[i].AutoSize = true;
                        lbTot[i].AutoSize = true;
                        lbSno1[i].AutoSize = true;
                        lbItm1[i].AutoSize = true;
                        lbQty1[i].AutoSize = true;
                        lbTot1[i].AutoSize = true;

                        lbSno[i].Font = new Font("ariel",6.5f, FontStyle.Regular)  ;
                        lbItm[i].Font = new Font("ariel",6.5f, FontStyle.Regular)  ;
                        lbQty[i].Font = new Font("ariel",6.5f, FontStyle.Regular)  ;
                        lbTot[i].Font = new Font("ariel",6.5f, FontStyle.Regular)  ;
                        lbSno1[i].Font = new Font("ariel",6.5f, FontStyle.Regular) ;
                        lbItm1[i].Font = new Font("ariel", 6.5f, FontStyle.Regular);
                        lbQty1[i].Font = new Font("ariel", 6.5f, FontStyle.Regular);
                        lbTot1[i].Font = new Font("ariel", 6.5f, FontStyle.Regular);

                        lbSno[i].Text = "" + (i + 1);
                        lbItm[i].Text = a.dataGridView4.Rows[i].Cells[1].Value.ToString();
                        lbQty[i].Text = a.dataGridView4.Rows[i].Cells[0].Value.ToString();
                        lbTot[i].Text = a.dataGridView4.Rows[i].Cells[2].Value.ToString();

                        lbSno1[i].Text = "" + (i + 1);
                        lbItm1[i].Text = a.dataGridView4.Rows[i].Cells[1].Value.ToString();
                        lbQty1[i].Text = a.dataGridView4.Rows[i].Cells[0].Value.ToString();
                        lbTot1[i].Text = a.dataGridView4.Rows[i].Cells[2].Value.ToString();

                        lbSno[0].Location = new Point(label6.Left + 5, label6.Bottom + 10);
                        lbItm[0].Location = new Point(label8.Left + 5, label8.Bottom + 10);
                        lbQty[0].Location = new Point(label10.Left + 5, label10.Bottom + 10);
                        lbTot[0].Location = new Point(label11.Left + 5, label11.Bottom + 10);

                        lbSno1[0].Location = new Point(label22.Left + 5, label22.Bottom + 10);
                        lbItm1[0].Location = new Point(label21.Left + 5, label21.Bottom + 10);
                        lbQty1[0].Location = new Point(label20.Left + 5, label20.Bottom + 10);
                        lbTot1[0].Location = new Point(label19.Left + 5, label19.Bottom + 10);

                        if (i != 0)
                        {
                            lbSno[i].Location = new Point(lbSno[i - 1].Left, lbSno[i - 1].Bottom + 5);
                            lbItm[i].Location = new Point(lbItm[i - 1].Left, lbItm[i - 1].Bottom + 5);
                            lbQty[i].Location = new Point(lbQty[i - 1].Left, lbQty[i - 1].Bottom + 5);
                            lbTot[i].Location = new Point(lbTot[i - 1].Left, lbTot[i - 1].Bottom + 5);
                            lbSno1[i].Location = new Point(lbSno1[i - 1].Left, lbSno1[i - 1].Bottom + 5);
                            lbItm1[i].Location = new Point(lbItm1[i - 1].Left, lbItm1[i - 1].Bottom + 5);
                            lbQty1[i].Location = new Point(lbQty1[i - 1].Left, lbQty1[i - 1].Bottom + 5);
                            lbTot1[i].Location = new Point(lbTot1[i - 1].Left, lbTot1[i - 1].Bottom + 5);
                        }

                        lbSno[i].Visible = true;
                        lbItm[i].Visible = true;
                        lbQty[i].Visible = true;
                        lbTot[i].Visible = true;
                        lbSno1[i].Visible = true;
                        lbItm1[i].Visible = true;
                        lbQty1[i].Visible = true;
                        lbTot1[i].Visible = true;

                        this.Controls.Add(lbSno[i]);
                        this.Controls.Add(lbItm[i]);
                        this.Controls.Add(lbQty[i]);
                        this.Controls.Add(lbTot[i]);
                        this.Controls.Add(lbSno1[i]);
                        this.Controls.Add(lbItm1[i]);
                        this.Controls.Add(lbQty1[i]);
                        this.Controls.Add(lbTot1[i]);

                        if (i == 13 || i == a.dataGridView4.RowCount - 1)
                        {
                            //try
                            //{
                            //    PrintDocument pdo = new PrintDocument();
                            //    pdo.PrintPage += new PrintPageEventHandler(PrintImage);

                            //    pdo.Print();

                            //}
                            //catch (Exception ee)
                            //{
                            //    MessageBox.Show(ee.Message);
                            //}

                        }



                    }
                    else if (i < 28)
                    {

                        lbSno[i - 14].Text = "" + (i + 1);
                        lbItm[i - 14].Text = a.dataGridView4.Rows[i].Cells[1].Value.ToString();
                        lbQty[i - 14].Text = a.dataGridView4.Rows[i].Cells[0].Value.ToString();
                        lbTot[i - 14].Text = a.dataGridView4.Rows[i].Cells[2].Value.ToString();
                        lbSno1[i - 14].Text = "" + (i + 1);
                        lbItm1[i - 14].Text = a.dataGridView4.Rows[i].Cells[1].Value.ToString();
                        lbQty1[i - 14].Text = a.dataGridView4.Rows[i].Cells[0].Value.ToString();
                        lbTot1[i - 14].Text = a.dataGridView4.Rows[i].Cells[2].Value.ToString();

                        if (i == 27 || i == a.dataGridView4.RowCount - 1)
                        {
                            for (int j = a.dataGridView4.RowCount; j <= 27; j++)
                            {

                                lbSno[j - 14].Visible = false;
                                lbItm[j - 14].Visible = false;
                                lbQty[j - 14].Visible = false;
                                lbTot[j - 14].Visible = false;
                                lbSno1[j - 14].Visible = false;
                                lbItm1[j - 14].Visible = false;
                                lbQty1[j - 14].Visible = false;
                                lbTot1[j - 14].Visible = false;
                            }
                            //try
                            //{
                            //    PrintDocument pdo = new PrintDocument();
                            //    pdo.PrintPage += new PrintPageEventHandler(PrintImage);
                            //    PrintPreviewDialog pdt = new PrintPreviewDialog();                 
                            //    pdo.Print();   
                            //}
                            //catch (Exception ee)
                            //{
                            //    MessageBox.Show(ee.Message);
                            //}
                        }
                    }
                    else
                    {

                    }
     
                }
            }
            catch { }
        }

i am using this code to print bill in a dot matrix printer,it prints bill on a half of full size page and the remaining page is ejected out i dont want that, i want to stop ejection after printing plz help

Edited 4 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

Yikes. Not only is that really hard to look at due to missing code tags, the code itself is terribly written! As for the printing problem - it seems more like a problem with printer configuration than with code. Try playing with your printer's page settings.

hey what's wrong in the code?...writing style or logic..? my only problem is that the dot matrix printer ejects the whole page after printing, i want it should not eject full paper

This article has been dead for over six months. Start a new discussion instead.