Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:52:12+00:00 2026-06-18T00:52:12+00:00

In c# window application I having a trouble with printing documents, when its become

  • 0

In c# window application I having a trouble with printing documents, when its become more than 1 page. See the following code which I am using for printing document and its working fine, while there is a small document i.e only one page.

On print button’s click event

    private void button1_Click(object sender, EventArgs e)
    {
        PrintDialog pd = new PrintDialog();
        PrintDocument doc = new PrintDocument();
        pd.Document = doc;
        doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
        DialogResult res = pd.ShowDialog();
        if (res == System.Windows.Forms.DialogResult.OK)
        {
            doc.Print();
        }
    }

And PrintPageEventHandler is as following.

    void doc_PrintPage(object sender, PrintPageEventArgs e)
    {
    //Fetching data from DB

        BillingApplicationEntities ent = new BillingApplicationEntities();
        List<tbCustBill> BillData = ent.tbCustBills.Where(s => s.BillId == 20133).ToList();

   //Printing doc

        Graphics grp = e.Graphics;

        Font fnt = new Font("Courier New", 12);
        float fontH = fnt.GetHeight();

        int startX = 10;
        int StartY = 10;
        int offset = 40;
        foreach (tbCustWorkDet d in WorkData)
        {
            string Pare = d.WorkName.PadRight(30);
            string pp = string.Format("{0:c}", d.Price).PadRight(30);

            string pl = Pare + pp;

            grp.DrawString(pl, fnt, new SolidBrush(Color.Black), startX, StartY + offset);

            offset += (int)fontH + 5;
           if (offsetY >= pageHeight)
           {
                e.HasMorePages = true;
                offsetY = 0;
                return; // you need to return, then it will go into this function again
           }
           else {
                 e.HasMorePages = false;
            }
        }
        offset += 20;
        // And cont with other data to print
    }

This method is working fine and gives me my required o/p, but when data becomes more larger and its need more pages to print then in o/p it gives me only one page.

As I think for multiple pages we have to set following property to true

    e.HasMorePages = true;

But I don’t know where and how to put this value…

In short I want to know how can I print multiple documents from above code?

In this code return will return to the function and entire execution start again, and so on this will become in Infinite loop. Please tell me how can I prevent with this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:52:13+00:00Added an answer on June 18, 2026 at 12:52 am

    Add e.HasMorePages = true; in the printpage handler, if there are more pages to print. This causes the handler to be called again. It is up to the handler to output the proper page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble deploying a Silverlight5 application. I'm releasing to a Windows server
I am developing window application in that I am having 2 child windows on
I ran dotTrace on my application (which is having some issues). IntPtr System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr,
In our application, we are having various windows which contain grid and their respective
Desktop window application. I have textbox in which user give values in numbers. what
I'm developing a window application in C# VS2005. I have a dataGridView in which
having trouble getting my directx going I get the following error 1>Linking... 1>main.obj :
I'm having trouble debugging my application because I can't even run it. I haven't
I'm having trouble with an application I'm writing in VS2010. I need to display
I'm having trouble with my application running into out of memory errors. I'm fairly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.