问题
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