我想使用c#.net通过打印机打印我的datagridview [英] i want to print my datagridview via printer using c#.net

查看:65
本文介绍了我想使用c#.net通过打印机打印我的datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;



我在visual studio 2008中使用c#。我想通过打印机打印我的datagridview,这里我附加了我的datagridview。请帮助我高级谢谢大家;)





http://s14.postimage.org/6onchp78x/tests.jpg

hi;

i am using c# in visual studio 2008. i want to print my datagridview via printer, here i have attached my datagridview. please help me advanced thanks for you all ;)


http://s14.postimage.org/6onchp78x/tests.jpg

推荐答案

首先,请看我对这个问题的评论。



正如你应该知道的那样,要在 System.Windows.Forms 应用程序中打印任何内容,您需要使用类 System.Drawing.Printing.PrintDocument

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



本MSDN帮助页面末尾的简单代码示例清楚地解释了如何做到这一点。



但我认为打印控制的想法与一些可用性误解有关。在大多数情况下,您需要打印数据,而不是面板,表单或直接复制UI外观的内容。纸质文件是纸质文件,屏幕是屏幕。我会解释一下。假设您的容器控件上有一个按钮和一个复选框,就像面板一样。在屏幕上,它可以单击复选框并更改状态,以及某些基础对象的状态,例如某些数据模型的某个实例。如果单击某个按钮,则可以触发某些处理,这可以执行与屏幕当前外观无关的操作,例如,处理现有数据并从中生成全新视图。在纸面上,您的用户可以点击什么?显示这些框和按钮只会令人困惑。这就是 PrintDocument 从控件中抽象出来的原因。


同时,外观 DataGridView 让你看起来非常接近你想要的印刷品。但还有其他问题。首先,布局应该是不同的。在打印时,您必须格式化数据以适应页面,这对于屏幕来说是非常不同的,特别是如果您需要表格跨越多个页面。



更多重要的是,这在UI层的体系结构和隔离方面是错误的。您需要一个单独的数据层。当您显示网格视图并填充它时,您可以从数据层执行此操作。同样,你应该从数据层而不是从UI创建打印。





祝你好运,

-SA
First of all, please see my comment to the question.

As you should already know, to print anything in your System.Windows.Forms application, you need to use the class System.Drawing.Printing.PrintDocument:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

A simple code sample at the end of this MSDN help page clearly explains how to do it.

But the idea of "printing of control", I think, is related to some usability misconception. In most cases, you need to print data, not the panel, form or something directly reproducing the look of your UI. Paper document is paper document, screen is screen. I''ll explain. Consider you have a button and a check box on your container control like a panel. On screen, it can click on check box and change is status, as well as the state of some underlying object, for example, some instance of some data model. If you click on a button, you can get trigger some processing, which can do something unrelated to a current look of your screen, for example, process existing data and generate completely new view out of it. On paper, what can your user to click on? Showing those boxes and buttons can only be confusing. That''s why PrintDocument is abstracted from the controls.

At the same time, the look of the DataGridView make look very close to what you want in print. But there are other problems. First, layout should be different. In print, you have to format data to fit the page, which is very different for screen, especially if you need the table to span more than one page.

More importantly, this is a wrong in terms of architecture and isolation of UI layer. You need to have a separate data layer. When you show your grid view and populated it, you do it from the data layer. Likewise, you should create a print from the data layer, not from UI.


Good luck,
—SA


打印datagridview [ ^ ]



打印DataGridView [ ^ ]


这篇关于我想使用c#.net通过打印机打印我的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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