如何在gridview打印文档中添加图像和文本? [英] How to add image and text to gridview print document?

查看:69
本文介绍了如何在gridview打印文档中添加图像和文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理winforms时,我正在尝试自定义gridview打印.从gridview的打印设置-打印外观部分不足以得到我想要的.我想绘制文本并将一些图像放置在页眉上.

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.

推荐答案

您要在纸上打印WinForms DataGridView的内容吗?这实际上是一项艰巨的任务,因为DataGridView是UI控件;它仅使每个单元格的部分在单元格矩形中可见,并且行数与视图矩形中显示的一样多.单元格和视图矩形均为固定大小.它还处理诸如滚动和编辑之类的事件.

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.

如果要将视图中的所有数据打印到一张纸上,则必须将所有单元格内容(甚至是未渲染的内容)对于所有行(甚至视图中未加载的行)显示为可变大小System.Drawing.Graphics实例大到足以容纳整个单元格内容,并组装单元格以适合固定大小的Page矩形,处理布局和分页,并避免Graphics矩形超出页面矩形.

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.

我的建议是使用报告生成库,例如报表查看器 nReports .

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.

这篇关于如何在gridview打印文档中添加图像和文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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