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

  • Home
  • SEARCH
  • 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 8308067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:41:15+00:00 2026-06-08T18:41:15+00:00

Coming from Question which was answered really quick, I have stumbled upon upgraded problem.

  • 0

Coming from Question

which was answered really quick, I have stumbled upon upgraded problem.

I have changed my program to fill some DataSet from DB.

I call Print() on printDocument, everything works, it just doesn’t want to register my e.HasMorePages = true;

Here is code:

   public static void printDokument()
   {
       if (result == DialogResult.OK)
       {

           DbDataPostavke = checkDB("SELECT * FROM " + tipDokumenta + "_postavke WHERE ID_" + tipDokumenta + " = " + stDokumenta);

           list = DbDataPostavke.Tables[0].AsEnumerable().ToList();                             
           printDocument.Print();
       }       
   }

   static void printDocument_PrintPage(object sender, PrintPageEventArgs e)
   {
       graphic = e.Graphics;

       e.PageSettings.PaperSize = ps;

       stranSirina = e.PageSettings.PrintableArea.Width;
       stranVisina = e.PageSettings.PrintableArea.Height;

       fontHeight = font.GetHeight();

       //this works/prints
       printDocument_PrintHeader();

       //this works/prints
       printDocument_PrintDocumentInfo();

       if (firstPage) printDocument_PrintSupplierInfo();    

       //Lines that I take from DB, amount of this lines is variable //it only prints one page, then it stops printing
       printDocument_PrintProductLines(e);

       //Sum of lines
       if(zadnjaStran) printDocument_printSum();

       //prints comment on document
       if (zadnjaStran) printDocument_PrintComment();

       //footer
       printDocument_PrintFooter();
   }

   static void printDocument_PrintProductLines(PrintPageEventArgs e)
   {
       //I print some stuff here (header, etc..) 

       String stranArtikliVrstica = String.Empty; // string for one line of data
       DataRow dataRow1 = null;
       DataRow dr = null;

       for(int i = 0; i < list.Count(); i++)
       {
           dr = list[i];
           dataRow1 = poglejBazo("SELECT ime, EM, opis FROM Sifrant WHERE ID = " + dr[2].ToString()).Tables[0].Rows[0];

           stranArtikliVrstica = String.Format("{0,-38}  {1,10}  {2,5}  {3,9:C}  {4,9:C}", dataRow1[0].ToString() + " - " + dataRow1[2].ToString(), dr[3].ToString(), dataRow1[1].ToString(), dr[4], Convert.ToInt16(dr[3]) * Convert.ToInt16(dr[4]));

           list.Remove(dr);

           graphic.DrawString(stranArtikliVrstica, font, brush, startX + offsetX, startY + offsetY);
           offsetY += (int)font.GetHeight();

           //if there is less then 35 "lines" remaining, we have enough space for printing some other stuff, otherwise, that stuff doesn't print..
           if (list.Count() < 35) zadnjaStran = true;
           else zadnjaStran = false;

           if (offsetY > stranVisina - 50)
           {
               prvaStran = false;
               stevecStrani++;
               offsetY = 0;
               e.HasMorePages = true;
               return;
           }
       }

   }

So, when I try to print a document with a single page, everything works, but if I try to print a document with multiple pages, only the first page prints (Header, DocumentInfo, SupplierInfo, ProductLines (around 38 lines out of 80), Footer) and then there is no more pages (I’m testing with printing into PDF file..)

What am I doing wrong?

Is there a problem with e parameter in PrintProductLines? How can I tell function PrintProductLines that I want to trigger HasMorePages on e from original function? I know I can pass it by reference, but ref keyword doesn’t work in my case :S

EDIT:

Changing static void printDocument_PrintProductLines(ref PrintPageEventArgs e) and printDocument_PrintProductLines(ref e); throws an error:

Error 2 Argument 1 must be passed with the ‘ref’ keyword
Error 1 The best overloaded method match for
‘GZIG.globalClass.printDocument_PrintPostavke(ref
System.Drawing.Printing.PrintPageEventArgs)’ has some invalid
arguments

  • 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-08T18:41:16+00:00Added an answer on June 8, 2026 at 6:41 pm

    You should not be placing printing code like this into a static global class.

    This routine belongs in the actual instance of the class that will be using the Graphics object.

    private const int PAD = 4;
    private int m_Line, m_LinesToPrint;
    private Font m_Font;
    private PrintDocument m_Doc;
    
    private void print_Click(object sender, EventArgs e) {
      using (var dlg = new PrintPreviewDialog()) {
        if (m_Doc == null) {
          throw new NullReferenceException("Create the document before trying to print it.");
        }
        dlg.Document = m_Doc;
        m_Line = 0;
        m_LinesToPrint = list.Count;
        m_Font = new Font("Courier New", 14, FontStyle.Underline, GraphicsUnit.Point);
        dlg.ShowDialog();
      }
    }
    
    private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) {
      float lineHeight = m_Font.GetHeight(e.Graphics) + PAD;
      float yLineTop = e.MarginBounds.Top;
      for ( ; m_Line < m_LinesToPrint; m_Line++) {
        if (e.MarginBounds.Bottom < (yLineTop + lineHeight)) {
          e.HasMorePages = true;
          return;
        }
        DataRow dr = list[m_Line];
        DataRow row1 = poglejBazo("SELECT ime, EM, opis FROM Sifrant WHERE ID = " + dr[2].ToString()).Tables[0].Rows[0];
        string strText = String.Format("{0,-38}  {1,10}  {2,5}  {3,9:C}  {4,9:C}", dataRow1[0].ToString() + " - " + dataRow1[2].ToString(), dr[3].ToString(), dataRow1[1].ToString(), dr[4], Convert.ToInt16(dr[3]) * Convert.ToInt16(dr[4]));
        // list.Remove(list[m_Line]) <= DO NOT DO THAT!
        e.Graphics.DrawString(strText, m_Font, Brushes.Black, new PointF(e.MarginBounds.Left, yLineTop));
        yLineTop += lineHeight;
      }
      e.HasMorePages = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for a badly-phrased question. I have a requirement coming from a non-technical person
I Have a set of choices(options) coming from Database(around 36 records) which I have
I have a question about Objective-C today involving NSMutableArray. Coming from a .net/c# background
I am following up from this question here The problem I have is that
Coming from the Java world, in which there are no typedefs, I have a
I'm coming largely from a c++ background, but I think this question applies to
I'm coming from a C++ background to python I have been declaring member variables
I have recently started learning C++ and coming from a Ruby environment I have
I have read a bit about casting in C++. Coming from a C background,
I need to parse the following xml document (which is coming from external web

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.