显示打印预览但不打印 [英] Show printing preview but not print
本文介绍了显示打印预览但不打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我
我用这个c#代码。它工作正常并显示打印预览但不打印总行。只打印标题。
Please help me
I use this c# Codes. It is work properly and display print preview but not print total row. Only print Header.
#region Draw Column 1
e.Graphics.FillRectangle(Brushes.LightGray, newRectangle(20, 380, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(Pens.Black, 20, 380, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Columns[0].HeaderText, dataGridView1.Font, Brushes.Black, newRectangleF(20, 380, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
#endregion
#region Draw Column 2
e.Graphics.FillRectangle(Brushes.LightGray, newRectangle(20 + dataGridView1.Columns[0].Width, 380, 200, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(Pens.Black, 20 + dataGridView1.Columns[0].Width, 380, 200, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Columns[1].HeaderText, dataGridView1.Font, Brushes.Black, newRectangleF(70 + dataGridView1.Columns[0].Width, 380, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
#endregion
#region Draw column 3
e.Graphics.FillRectangle(Brushes.LightGray, newRectangle(220 + dataGridView1.Columns[0].Width, 380, 100, dataGridView1.Rows[0].Height));
e.Graphics.DrawRectangle(Pens.Black, 220 + dataGridView1.Columns[0].Width, 380, 100, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Columns[2].HeaderText, dataGridView1.Font, Brushes.Black, newRectangleF(250 + dataGridView1.Columns[0].Width, 385, dataGridView1.Columns[2].Width, dataGridView1.Rows[0].Height), str);
width = 200 + dataGridView2.Columns[0].Width;
height = 380;
//variable i is declared at class level to preserve the value of i if e.hasmorepages is true
while (i < dataGridView3.Rows.Count)
{
if (height > e.MarginBounds.Height)
{
height = 380;
width = 300;
e.HasMorePages = true;
return;
}
height += dataGridView1.Rows[i].Height;
e.Graphics.DrawRectangle(Pens.Black, 20, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[0].FormattedValue.ToString(), dataGridView1.Font, Brushes.Black, newRectangleF(20, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
e.Graphics.DrawRectangle(Pens.Black, 20 + dataGridView1.Columns[0].Width, height, 300, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[1].Value.ToString(), dataGridView1.Font, Brushes.Black, newRectangleF(20 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
e.Graphics.DrawRectangle(Pens.Black, 220 + dataGridView1.Columns[0].Width, height, 100, dataGridView1.Rows[0].Height);
e.Graphics.DrawString(dataGridView1.Rows[i].Cells[2].Value.ToString(), dataGridView1.Font, Brushes.Black, newRectangleF(250 + dataGridView1.Columns[0].Width, height, dataGridView1.Columns[0].Width, dataGridView1.Rows[0].Height), str);
width += dataGridView1.Columns[0].Width;
i++;
#endregion
推荐答案
WinForms解决方案
-----------------------
我'我更喜欢使用 PrintForm类 [ ^ ],在运行时打印Windows窗体的图像。
Solution for WinForms
-----------------------
I''ll prefer to use PrintForm class[^], which enables printing an image of a Windows Form at run time.
这篇关于显示打印预览但不打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文