PsychoFader Ответов: 1

Как мне распечатать все страницы?


Я пытаюсь напечатать 3 страницы в одном документе, но он печатает только мою последнюю страницу.

private void button4_Click(object sender, EventArgs e)
{
    if (textBox1.Text != "" || textBox2.Text != "" || richTextBox1.Text != "" || Imagemfoot_1.Image != null || Imagemfoot_2.Image != null || Imagemfoot_3.Image != null || Imagemhead_1.Image != null || Imagemhead_2.Image != null || Imagemhead_3.Image != null)
    {
        PrintDocument tPrinter = new PrintDocument();
        tPrinter.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
        tPrinter.Print();

    }
}


Что я уже пробовал:

это мой код.:

switch (PageNumber)
                   {
                       case 1:
                           /// Imagens de header
                           if (numericUpDown1.Value == 1)
                           {
                               e.Graphics.DrawImage(Imagemhead_3.Image, x2, y2, width2, height2);
                           }

                           else if (numericUpDown1.Value == 2)
                           {
                               e.Graphics.DrawImage(Imagemhead_1.Image, x3, y3, width3, height3);
                               e.Graphics.DrawImage(Imagemhead_2.Image, x4, y4, width4, height4);
                           }

                           /// Titulo
                           string stringToPrint = textBox1.Text;
                           StringFormat sf = new StringFormat();
                           sf.Alignment = StringAlignment.Center;

                           Font drawFont = new Font("Calibri", 32, FontStyle.Bold);
                           SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.FromArgb(78, 87, 88));

                           System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 540, 830, 100);

                           e.Graphics.DrawString(stringToPrint, drawFont, drawBrush, rect, sf);

                           /// Duração
                           string stringToPrint2 = textBox2.Text;
                           StringFormat sf2 = new StringFormat();
                           sf2.Alignment = StringAlignment.Center;

                           Font drawFont2 = new Font("Calibri", 20, FontStyle.Bold, GraphicsUnit.Pixel);
                           SolidBrush drawBrush2 = new SolidBrush(System.Drawing.Color.FromArgb(98, 166, 10));

                           System.Drawing.RectangleF rect2 = new System.Drawing.RectangleF(0, 595, 830, 100);

                           e.Graphics.DrawString(stringToPrint2, drawFont2, drawBrush2, rect2, sf2);

                           /// Pequena descrição

                           string infoString = "";  // enough space for one line of output
                           int descent;            // font family descent in design units
                           int lineSpacing;        // font family line spacing in design units
                           float lineSpacingPixel; // line spacing converted to pixels

                           FontFamily fontFamily = new FontFamily("Calibri Light");
                           Font font = new Font(richTextBox1.Font.FontFamily, richTextBox1.Font.Size, FontStyle.Regular, GraphicsUnit.Pixel);
                           System.Drawing.RectangleF rect3 = new System.Drawing.RectangleF(10, 450, 800, 350);
                           SolidBrush solidBrush = new SolidBrush(Color.Black);

                           // Move down five lines.
                           rect3.Y += 5 * font.Height;

                           // Display the descent in design units and pixels.
                           descent = fontFamily.GetCellDescent(FontStyle.Regular);

                           // Display the line spacing in design units and pixels.
                           lineSpacing = fontFamily.GetLineSpacing(FontStyle.Regular);

                           // Move down one line.
                           rect3.Y += 5 * font.Height;

                           // 18.398438 = 16.0 * 2355 / 2048
                           lineSpacingPixel =
                           font.Size * lineSpacing / fontFamily.GetEmHeight(FontStyle.Regular);
                           infoString = richTextBox1.Text.Trim();
                           e.Graphics.DrawString(infoString, font, solidBrush, rect3);

                           /// Imagens Footer

                           e.Graphics.DrawImage(Imagemfoot_1.Image, x5, y5, width5, height5);
                           e.Graphics.DrawImage(Imagemfoot_2.Image, x6, y6, width6, height6);
                           e.Graphics.DrawImage(Imagemfoot_3.Image, x7, y7, width7, height7);

                           /// Footer Logo

                           e.Graphics.DrawImage(Logo_Footer.Image, x8, y8, width8, height8);

                           PageNumber++;
                           e.HasMorePages = true;
                           return;

                       case 2:
                           PageNumber++;
                           e.HasMorePages = true;

                           return;

                       case 3:
                           PageNumber++;
                           e.HasMorePages = true;

                           return;

                       case 4:
                           /// Descrições

                           /// Titulo
                           string stringToPrint5 = textBox1.Text;
                           StringFormat sf5 = new StringFormat();
                           sf5.Alignment = StringAlignment.Center;

                           Font drawFont5 = new Font("Calibri", 32, FontStyle.Bold);
                           SolidBrush drawBrush5 = new SolidBrush(System.Drawing.Color.FromArgb(78, 87, 88));

                           System.Drawing.RectangleF rect5 = new System.Drawing.RectangleF(0, 540, 830, 100);

                           e.Graphics.DrawString(stringToPrint5, drawFont5, drawBrush5, rect5, sf5);

                           /// Imagens Footer

                           e.Graphics.DrawImage(Imagemfoot_1.Image, x5, y5, width5, height5);
                           e.Graphics.DrawImage(Imagemfoot_2.Image, x6, y6, width6, height6);
                           e.Graphics.DrawImage(Imagemfoot_3.Image, x7, y7, width7, height7);

                           /// Footer Logo

                           e.Graphics.DrawImage(Logo_Footer.Image, x8, y8, width8, height8);

                           PageNumber++;
                           e.HasMorePages = true;
                           return;

                       case 5:
                           /// Custos

                           /// Titulo
                           string stringToPrint6 = textBox1.Text;
                           StringFormat sf6 = new StringFormat();
                           sf6.Alignment = StringAlignment.Center;

                           Font drawFont6 = new Font("Calibri", 32, FontStyle.Bold);
                           SolidBrush drawBrush6 = new SolidBrush(System.Drawing.Color.FromArgb(78, 87, 88));

                           System.Drawing.RectangleF rect6 = new System.Drawing.RectangleF(0, 90, 830, 100);

                           e.Graphics.DrawString(stringToPrint6, drawFont6, drawBrush6, rect6, sf6);

                           /// Duração
                           string stringToPrint7 = textBox2.Text;
                           StringFormat sf7 = new StringFormat();
                           sf7.Alignment = StringAlignment.Center;

                           Font drawFont7 = new Font("Calibri", 20, FontStyle.Bold, GraphicsUnit.Pixel);
                           SolidBrush drawBrush7 = new SolidBrush(System.Drawing.Color.FromArgb(98, 166, 10));

                           System.Drawing.RectangleF rect7 = new System.Drawing.RectangleF(0, 145, 830, 100);

                           e.Graphics.DrawString(stringToPrint7, drawFont7, drawBrush7, rect7, sf7);

                           /// Termos Condições
                           string stringToPrint8 = "Rates and conditions";
                           StringFormat sf8 = new StringFormat();
                           sf8.LineAlignment = StringAlignment.Center;
                           sf8.Alignment = StringAlignment.Center;

                           Font drawFont8 = new Font("Calibri", 25, FontStyle.Bold, GraphicsUnit.Pixel);
                           SolidBrush drawBrush8 = new SolidBrush(System.Drawing.Color.White);

                           System.Drawing.RectangleF rect8 = new System.Drawing.RectangleF(0, 180, 830, 45);
                           e.Graphics.FillRectangle(drawBrush6, rect8);

                           e.Graphics.DrawString(stringToPrint8, drawFont8, drawBrush8, rect8, sf8);

                           /// Tabela

                           e.Graphics.DrawImage(pictureBox3.Image, x9, y9, width9, height9);

                           /// Fontes e StringFormats da tabela

                           /// Font Header2
                           StringFormat sfH2 = new StringFormat();
                           sfH2.Alignment = StringAlignment.Center;
                           Font drawFontH2 = new Font("Calibri Light", 20, FontStyle.Bold, GraphicsUnit.Pixel);
                           SolidBrush drawBrushH2 = new SolidBrush(System.Drawing.Color.White);

                           System.Drawing.RectangleF rectH21 = new System.Drawing.RectangleF(280, 250, 120, 50);
                           System.Drawing.RectangleF rectH22 = new System.Drawing.RectangleF(600, 250, 120, 50);

                           e.Graphics.DrawString(textBox3.Text, drawFontH2, drawBrushH2, rectH21, sfH2);
                           e.Graphics.DrawString(textBox4.Text, drawFontH2, drawBrushH2, rectH22, sfH2);

                           /// Imagens Footer

                           e.Graphics.DrawImage(Imagemfoot_1.Image, x5, y5, width5, height5);
                           e.Graphics.DrawImage(Imagemfoot_2.Image, x6, y6, width6, height6);
                           e.Graphics.DrawImage(Imagemfoot_3.Image, x7, y7, width7, height7);

                           /// Footer Logo

                           e.Graphics.DrawImage(Logo_Footer.Image, x8, y8, width8, height8);

                           e.HasMorePages = false;
                           return;
                   }

1 Ответов

Рейтинг:
9

OriginalGriff

Что ж... страницы 2 и 3 ничего не печатают, поэтому они будут пустыми.

Кроме этого, используйте отладчик для выполнения двух задач:
1) проверьте значение PageNumber в вашем обработчике событий нажатия кнопки. Вы не показываете никакого кода для его настройки или сброса, так что это может быть так просто.
2) поместите точку останова в верхней части обработчика событий PrintPage и шагните через код, чтобы точно узнать, куда он идет.

Мы не можем сделать это для вас - у нас нет никакого доступа к вашей машине!