forum

Home / DeveloperSection / Forums / C# winform Printing Multipage Margin not set

C# winform Printing Multipage Margin not set

Tech Sys 2370 16-Oct-2014
Hi,

iam using below code for printing ,plz see in the attached image,there is 3 pages .
1st page is ok
2 page should be print only names without any header top margin is 100
also same as 3rd page.

here is my code

 string strDisplay = "Students Details";
                System.Drawing.Font fntString = new Font("Times New Roman", 28, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay, fntString, Brushes.Black, 250, 100);
                e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 184, 700, 184);
                e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 188, 700, 188);
                string strDisplay1 = "Company name :";
                System.Drawing.Font fntString1 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay1, fntString1, Brushes.Black, 100, 200);
                string strDisplay2 = "Address :";
                System.Drawing.Font fntString2 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay2, fntString2, Brushes.Black, 100, 250);
                string strDisplay3 = "City :";
                System.Drawing.Font fntString3 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString(strDisplay3, fntString3, Brushes.Black, 100, 300);
                e.Graphics.DrawLine(new Pen(Color.Black, 1), 60, 350, 700, 350);
               
                System.Drawing.Font fntString4 = new Font("Times New Roman", 16, FontStyle.Bold);
                e.Graphics.DrawString("Student Name"+"\n"+"--------------------", fntString4, Brushes.Black, 100, 400);
           
            
                float linesPerPage = 0;
                float yPosition = 450;
                int count = 0;
                float leftMargin = 100;
                float topMargin = 450;
                string line = null;
                Font printFont = new System.Drawing.Font("Times New Roman", 8, FontStyle.Regular);
                SolidBrush myBrush = new SolidBrush(Color.Black);


                linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
                while (count < linesPerPage && ((line = myReader.ReadLine()) != null))
                {
                    yPosition = topMargin + (count * printFont.GetHeight(e.Graphics));
                    e.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, new StringFormat());
                    count++;
                }
                if (line != null)
                {
                    e.HasMorePages = true;
                }
                else
                {
                    e.HasMorePages = false;
                }
                myBrush.Dispose();
            }
        }
C# winform Printing Multipage Margin not set

Please could anybody solve this problem,this is urgent

rgds
Deziner2000

Updated on 03-Nov-2014

Can you answer this question?


Answer

8 Answers

Liked By