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 8060721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:05:10+00:00 2026-06-05T10:05:10+00:00

Good day to all, I have an application that creates a report for daily

  • 0

Good day to all,
I have an application that creates a report for daily time record of an employee.
The problem is all of the pages in printpreview dialog were overwritting by every pages that available in printing. how can i possibly solve this kind of issue? The content of page 1 is for page 1, page 2 is for page 2 only and vise versa.
Here is my code for printing:

    private void simpleButtonOk_Click(object sender, EventArgs e)
    {
        try
        {
            countPage = 0;
            CoolPrintPreviewDialog printPreview = new CoolPrintPreviewDialog();
            PrintDocument doc = new PrintDocument();
            doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
            printPreview.Document = doc;
            Form p = (Form)printPreview;
            p.WindowState = FormWindowState.Maximized;
            p.ShowDialog();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    void doc_PrintPage(object sender, PrintPageEventArgs e)
    {
        try
        {
            for (int i = 1; i <= countEmployee; i++)
            {
                Font fontName = new Font("Calibri", 12, FontStyle.Bold);
                Font fontPosition = new Font("Calibri", 12, FontStyle.Regular);
                Brush colorBrush = new SolidBrush(Color.Black);

                e.Graphics.DrawString(empName, fontName, colorBrush, new Point(80, 120));
                e.Graphics.DrawString(empPosition, fontPosition, colorBrush, new Point(80, 140));
                e.Graphics.DrawString(empId, fontPosition, colorBrush, new Point(680, 120));
                DataManipulation.PrintSelectEmployeeByMonth(i, e, comboBoxMonth, comboBoxYear, comboBoxDayFrom, comboBoxDayTo);
                countPage++;
                MessageBox.Show(countPage.ToString());
            }
            if (countPage <= countEmployee)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
            }

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
  • 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-05T10:05:12+00:00Added an answer on June 5, 2026 at 10:05 am

    The PrintPage event is raised once for each page; your for loop suggests that you are trying to print all the pages whenever the event is raised.

    You need to remove the for loop and promote the index variable i to an instance-level variable that you can use to track the current page number.

    The remainder of your code appears to be correct; you must keep requesting more pages until the event has been fired countEmployee times.

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

Sidebar

Related Questions

Good day all, I have written an application that i require to have a
Good day to all, I have the following problem I have to convert the
Good day everyone. I have been having the same problem all day at work
Good day to all. I have the flowing problem. I have 2 domains. On
Good day all, first of all, what am trying to do is have an
Good day, all. I know that this is a pretty basic question in terms
Good day, I have a class that implements the LoaderCallbacks, and hence have the
Good day all I have the following question: I would like to use Chart
Good day to all. I have this structure <html> <iframe> <div id=idd>Some Content</div> </iframe>
Good day to all. I have a question, i'm using wpf and i cant

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.