PrintPreviewDialog生成打印预览时出现问题 [英] PrintPreviewDialog Problem in generating print previews

查看:764
本文介绍了PrintPreviewDialog生成打印预览时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果页面大于1并按下按钮,打印预览不会停止生成打印预览,只有按下取消按钮才会停止,然后它会显示超过1页的表格但内部数据表格是一样的。如何解决这个不断生成打印预览和重复数据的打印预览问题?提前谢谢:D $ / $


if the pages is more than 1 and i press a button the print preview don't stop generating print preview it will only stop if press the cancel button, then it will display the table with more than 1 pages but the data inside the tables is just the same. how can i solve this print preview problem that keeps generating print preview and the repetition of data?? thank you in advance :D

private void button3_Click(object sender, EventArgs e)
 {  printPreviewDialog1.ShowDialog();  }





这是我的PrintDocument中的代码:





here is the code in my PrintDocument:

else if (radioButton2.Checked)
            {

                while (i < dataGridView1.Rows.Count)
                {

                      if (height > e.MarginBounds.Height)
                    {
                        height = 130;
                        width = 100;
                        e.HasMorePages = true;
                        return; }

                    else

                    { e.HasMorePages = false;   }

                    //Draws a rectangle with same width and height of first column of datagridview. 
                    e.Graphics.DrawRectangle(Pens.Black, 100, 0,
                        dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height);

                    //Fills the above drawn rectangle with a light gray colour just to distinguish the header 
                    e.Graphics.FillRectangle(Brushes.LightGray, new Rectangle
                        (100, 0, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));

                    //Draws a text inside the above drawn rectangle whose value is same of the first column. 

                    e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText,
                        dataGridView1.Font, Brushes.Black, new RectangleF(100, 0,
                        dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);



                    height += dataGridView1.Rows[i].Height;

                    e.Graphics.DrawRectangle(Pens.Black, 100, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height);
                    e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, new RectangleF(100, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);


                    width += dataGridView1.Columns[0].Width;
                    i++;

                }

            }

推荐答案

我在尝试时看到问题出现了在打印硬拷贝时,使用页面编号更正打印预览问题,而不是重新启动。如果这对你有帮助,在DrawRows函数中,我需要重置PageNumber和mColumnPoints。

I saw that problem appear when I attempted to correct a printpreview issue with page numbering that continued vs. restarting when printing the hardcopy. In case this helps you, in DrawRows function, I needed to reset PageNumber and mColumnPoints.
   CurrentRow = 0
   mColumnPoint += 1
 'Continue to print the next group of columns
If mColumnPoint = mColumnPoints.Count Then
  'Which means all columns are printed
    mColumnPoint = 0

    PageNumber = 0
    mColumnPoints.Clear()

    Return False
Else
    Return True
End If





祝你好运!



Good luck!


这篇关于PrintPreviewDialog生成打印预览时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆