Click here to Skip to main content
15,796,738 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

this is my print document code

string strDisplay = "Printing Index";
            System.Drawing.Font fntString = new Font("Times New Roman", 28, FontStyle.Bold);
            e.Graphics.DrawString(strDisplay, fntString, Brushes.Black, 180, 100);

fntString = new System.Drawing.Font("Times New Roman", 12, FontStyle.Regular);
            e.Graphics.DrawString("DESCRIPTION" + "\n" + "--------------------------" + "\n" + textBox1.Text + "\n" + "--------------------------" + "\n" + textBox1.Text + "\n" + "--------------------------", fntString, Brushes.Black, 70, 590);
float linesPerPage = 0;
            float yPosition = 590;
            int count = 0;
            float leftMargin = 70;
            float topMargin = 590;
            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());

            if (line != null)
                e.HasMorePages = true;
                e.HasMorePages = false;

textbox1 content shown in first pages start top margin 590 and also print in second page also top margin is 590,i want first page top margin is 590 and second page contiuned to top position only not it 590

i stuck here plz help
Richard MacCutchan 20-Sep-14 3:47am    
You need to count the pages as you print, and adjust the margin after printing the first page.
cadsolution 20-Sep-14 3:51am    
its print in first page correctly what i need margin i.e top margin = 590,but problem is second page also print same position i e. top margin 590,i want to print second page top margin is to be continued from 100

1 solution

you should maintain a flag on page level
bool isFirstPagePrinted = false;

when first time event called...
  yPosition = 590;
  topMargin = 590;
  isFirstPagePrinted = true;
  yPosition = 100;
  topMargin = 100;

Hope this approch will be helpful
you can reset
isFirstPagePrinted = false;

on click of your "print" button
Happy coding! :)
Share this answer
cadsolution 22-Sep-14 1:52am    
iam tryieng but my problem is not solved,plz help me.
Aarti Meswania 22-Sep-14 4:50am    
what is issue are all pages having 590 margin or 100?
cadsolution 22-Sep-14 6:02am    
all pages 590 margin
but i want first page 590 margin and continued to next page 100 margin
Aarti Meswania 22-Sep-14 6:09am    
first of all find "no. of pages" to be printed
cadsolution 22-Sep-14 6:35am    
no of pages we dont know,may be 5 or more but pages are as per enterd text in textbox

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