How to add image and text to gridview print document? [closed]

本小妞迷上赌 提交于 2020-03-05 05:34:44

问题


Working on winforms, I'm trying to customize gridview print. The print settings - print apparance section from gridview is not enough to get that i want. I want to draw text and put some images to header.


回答1:


You’re trying to print the contents of a WinForms DataGridView to paper? That is actually a difficult task because a DataGridView is a UI control; it renders only the parts of each cell visible in the cell rectangle for as many rows as are displayed in the view rectangle. Both the cell and view rectangles are fixed sizes. It also handles events like scrolling and editing.

If you want to print all the data in the view to a piece of paper, you will have to show all cell contents, even contents not rendered, for all rows, even rows not loaded in the view, to variable-sized System.Drawing.Graphics instances large enough to hold the entire cell contents, and assemble the cells to fit in a fixed-size Page rectangle, handling layout and pagination, and avoiding Graphics rectangles outside the page rectangle.

My advice is to use a report generation library like Report Viewer or nReports.

If you're just learning printing, or have extremely simple needs, you can simply loop through your data and draw the cell contents to fixed margins on the paper; there is a Code Project article on doing this.



来源:https://stackoverflow.com/questions/21835039/how-to-add-image-and-text-to-gridview-print-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!