系统必须能够以c#打印报告。 [英] The system must be able to print a report in c#.

查看:119
本文介绍了系统必须能够以c#打印报告。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助编写如何打印报告的代码。

到目前为止我已经有了这个,但是当我打印时,我只是打印空白页...

Hi, i need help with coding on how to print a report.
I've got this so far, but when i print, i just print blank pages..

private void button1_Click(object sender, EventArgs e)
{
    this.printDialog1.Document = this.printDocument1;
    DialogResult dr = this.printDialog1.ShowDialog();

    string PrintPathe = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
    FileToPrint = new System.IO.StreamReader(PrintPathe + @"\Print.txt");
    PrintFont = new System.Drawing.Font("Arial",10);
    printDocument1.Print();



    //printPreviewDialog1.Document = ;
    printDocument1.DocumentName = (PrintPathe + @"\\Print.txt");
    printPreviewDialog1.ShowDialog();

    FileToPrint.Close();

}



Thanx *


Thanx*

推荐答案

这是因为你没有写一行将任何内容放在打印文档中。请仔细阅读: http://msdn.microsoft.com/en-us/ library / system.drawing.printing.printdocument.aspx [ ^ ]。



请参阅本文末尾的代码示例。它显示了如何处理事件 PrintPage 并使用类 System.Drawing.Graphics 的实例来放置一些图形在页面上。在这个例子中,带有 ev.Graphics.DrawString 的行是唯一一个将某些内容放在页面上的行,而在你的代码中根本就没有这样的内容。 。难怪它打印空白页。



-SA
This is because you did not write a single line putting any content in print document. Please read carefully: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

Please see the code sample at the end of this article. It shows how to handle the event PrintPage and use the instance of the class System.Drawing.Graphics to put some graphics on the page. In this example, the line with "ev.Graphics.DrawString" is the only line where some content is put on page, and in your code there is nothing like that at all. No wonder it "prints" blank pages.

—SA


这篇关于系统必须能够以c#打印报告。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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