且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何打印Windows窗体和appearabe datagridview

更新时间:2023-12-06 12:28:40

即使在CodeProject上,你也可以找到很多相关的代码:

http:// www .codeproject.com / search.aspx?q = print + form +%22C%23%22& doctypeid = 1& sort = createddesc [ ^ ],

http://www.codeproject.com/search.aspx?q = print + DataGridView +%22C%23%22& doctypeid = 1 [ ^ ]。



特别是:

以报告方式打印表单(2.2版) [ ^ ],

表格打印控制 [ ^ ],

打印任何控件的组件,包括ListViews,TreeViews,DataGridViews和Forms [ ^ ],

用C#简化.NET打印 [ ^ ],

打印DataGridView [ ^ ],

使用API​​打印Windows窗体 [ ^ ],

FormPrint作为一个简单的类 [ ^ ] 。



但是,在许多情况下,打印数据可能是一个好主意,而不是表格。您可以打印数据源中的数据,用于填充UI或绑定到的数据,而不是UI本身。所有你需要知道的是类 System.Drawing.Printing.PrintDocument

http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx [ ^ ]。



您可以在本MSDN文章末尾找到有用的代码示例。



- SA

hi friends,
i have a windows form with some labels and a datagridview with automatic appearaable scrollbar(in fact many information on datagridview that does not shown in datagrid view until user scroll down). my problem is this that i want to print all information of windows form with some rows of datagridview in first page and other rows of datagridview with windows form controls(some labels on it) in page 2 or 3 or ... . what i must do?
thank you.

Even on CodeProject along, you can find a lot of relevant code:
http://www.codeproject.com/search.aspx?q=print+form+%22C%23%22&doctypeid=1&sort=createddesc[^],
http://www.codeproject.com/search.aspx?q=print+DataGridView+%22C%23%22&doctypeid=1[^].

In particular:
Printing a Form in a report fashion (release 2.2)[^],
Form Print Control[^],
A component that prints any control, including ListViews, TreeViews, DataGridViews, and Forms[^],
Simplified .NET Printing in C#[^],
Printing of DataGridView[^],
Print Windows Forms w/o using API[^],
FormPrint as a simple class[^].

However, for many cases, it's probably a good idea to print data, not a form. You can print the data from your data source, the same data you used to populate your UI or bind to it, not the UI itself. All you need to know is the class System.Drawing.Printing.PrintDocument:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

You can find a useful code sample at the end of this MSDN article.

—SA