如何在C#中添加打印功能 [英] How to add print functionality in C#

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

问题描述

大家好,我正在研究C#的中期项目,这是保留一个商店的记录,在这里我有一个Winform应用程序有一个DataGridView和一些控件除了打印功能外,一切都很完整。

以下是WinForm的链接: WinForm的链接

我想从控件中打印DataGrid和信息,DataGrid中有一些隐藏的列,我也想隐藏在页面上。

第一页必须包含与静态相关的公司信息,以及相应更改的供应商信息。如果有多个页面,我想在最后一页添加页眉和总计。

here关于账单格式的链接我想要达到的目的不完全是这样的:

帐单格式链接



我尝试了什么:



我试过PrintDocument跟随tutt,但事实证明设计一个页面对我来说是噩梦使用e.graphics .....画上坐标我必须再次运行应用程序n再看看我是否正确。

Hello guys,i am working on mid-Term project in C#, this is keeping record of a shop and itand in this I have a Winform application There is a DataGridView and some Controls everything is complete except printing functionality.
Here is link of WinForm : Link of WinForm
I want to Print DataGrid and information from controls, there are some hidden columns in DataGrid which i also want to hide on page.
1st page must contain Company information which is like static,and Supplier information which changes from accordingly.I want to add page header and Total on last page if multiple pages.
here is link about bill format i want to achieve not exactly but something like this:
Link of Bill Format

What I have tried:

I tried PrintDocument following tutt but it turns out designing a page is nightmare for me using e.graphics.....drawing on Coordinates i have to run application again n again to see if i m doing right.

推荐答案

引用:

在坐标上绘图我必须再次运行应用程序n再看看我是否正确

drawing on Coordinates i have to run application again n again to see if i m doing right



是的 - 因为你试图让布局正确。



最简单的解决方案是实现打印预览(因为它使用相同的代码,但打印到显示器,这样你可以轻松快速地看到你有什么。

然后添加一个PDF打印驱动程序(谷歌会找到你很多)并打印到那个而不是一个真正的打印机用于测试 - 它不会像喷墨一样填满房间垃圾。



但首先要在纸上手动布置页面d从中工作以使您的打印例程正常工作。



所有这些都有替代方案 - 您可以添加一个PrintForm组件:如何:使用PrintForm组件(Visual Basic)打印表单Microsoft Docs [ ^ ]

BUT - 这是一个很大的但是很大!不要试图使用它。它打印出你看到的表格,所以如果你的数据的一半滚动到DataGridView的底部,那么它就不会打印出来了,你可以把组件打印出去!

坚持使用PrintDocument - 它可能看起来很笨拙,但它非常非常有效!


Yes - because you are trying to get the layout correct.

The simplest solution is to implement print preview (as it uses the same code, but prints to the display so it's easy and quick to see what you have.
Then add a PDF print driver (google will find you quite a few) and print to that instead of a genuine printer for testing - it doesn't fill the room with rubbish like an inkjet will.

But start by laying out your page manually on paper and work from that to get your print routine working.

There is an "alternative" to all this - there is a PrintForm component you can add: How to: Print a Form by Using the PrintForm Component (Visual Basic) | Microsoft Docs[^]
BUT - and it's a big BUT! Don't be tempted to use it. It prints the form as you see it, so if half your data is scrolled off the bottom of the DataGridView then it will not get printed, and you can;t make the component print it at all!
Persevere with PrintDocument - it may seem clumsy, but it's very, very effective!


这篇关于如何在C#中添加打印功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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