【问题标题】:how to print something that is not shown on the screen如何打印屏幕上未显示的内容
【发布时间】:2013-04-14 15:08:12
【问题描述】:

我一直在为打印文档而苦苦挣扎, 文档有页眉页脚和正文, 正文(这是一个网格)对于每个不同的文档都有不同的大小。 根据网格的行数,文档可能具有 2 种尺寸(A5、A4)中的一种

我一开始用的是 ReportViewer 控件,但有一些问题,主要是打印 2 篇论文,无论文档大小如何,经过 10 周的研究我放弃了,没有任何意义。

然后我尝试打印一个表格,它的所有内容(这并不容易)再次浮出水面, 其中之一是不同的屏幕分辨率,更糟糕的是,如果正文有很多行,表格将不适合屏幕,那么它将不会被打印。

我的问题是:
word如何打印页面的所有内容?机制是什么? 我只是需要一个先机,如何打印屏幕上未显示的内容?

【问题讨论】:

  • 我终于找到了一种使用 WPF 的方法,完成后我会发布我的代码。

标签: c# wpf winforms printing


【解决方案1】:

我不确定这是不是你想要的,但是,

您需要做的是创建一个与您要打印的控件大小相同的虚拟表单,然后将控件添加到虚拟表单并显示该表单并在虚拟表单上打印控件。

我是这样做的:

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    //Create bitmap
    Bitmap image = new Bitmap(dataGridView1.Width, dataGridView1.Height);
    //Create form
    Form f = new Form();
    //add datagridview to the form
    f.Controls.Add(dataGridView1);
    //set the size of the form to the size of the datagridview
    f.Size = dataGridView1.Size;
    //draw the datagridview to the bitmap
    dataGridView1.DrawToBitmap(image, new Rectangle(0, 0, dataGridView1.Width, dataGridView1.Height));
    //dispose the form
    f.Dispose();
    //print
    e.Graphics.DrawImage(image, 0, 0);
}

这将打印 dataGridView1,即使它在表单上看不到。

【讨论】:

  • 如果这项工作将节省我大量的时间,谢谢!我会试试看。
猜你喜欢
  • 2019-03-07
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
  • 1970-01-01
  • 2019-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多