0
Answer

How printing multipages from a listBox C#?

rafal

rafal

14y
3.4k
1
Hi
I can`t print more pages, only one page.


This is my code :/



 private void printDocument1_PrintPage_1(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            float linesPerPage = 0;
            float yPos = 0;
            int i = 0;
            float leftMargin = e.MarginBounds.Left;
            float topMargin = e.MarginBounds.Top;
            string line = null;
            SolidBrush myBrush = new SolidBrush(Color.Black);
            Font printFont = this.listBox1.Font;
            linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);
            while (i < linesPerPage && i < listBox1.Items.Count)
            {
                yPos = topMargin + (i * printFont.GetHeight(e.Graphics));
                line = listBox1.Items[i].ToString();
                e.Graphics.DrawString(line, printFont, Brushes.Black,leftMargin, yPos, new StringFormat());
                i++;
            }
            if (i <= listBox1.Items.Count)
                e.HasMorePages = true;
            else
            {
                e.HasMorePages = false;
                i = 0;
            }
        }


what is wrong?
Pleas, help me :(