《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)

《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)

ID:6670031

大小:30.00 KB

页数:5页

时间:2018-01-21

《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)_第1页
《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)_第2页
《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)_第3页
《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)_第4页
《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)_第5页
资源描述:

《《编程知识总结》25—在c#中实现打印功能(c#中printdialog,printdocument的使用)》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库

1、《编程知识总结》25—在C#中实现打印功能(C#中PrintDialog,PrintDocument的使用)在C#中实现打印功能(C#中PrintDialog,PrintDocument的使用)在c#中使用printdialog可以很方便的实现程序的打印功能。其步骤如下:创建一个printdialog的实例。如下:system.windows.forms.printdialogprintdialog1=newprintdialog();创建一个printdocument的实例.如下:system.drawing.printing.printdocu

2、mentdoctoprint=newsystem.drawing.printing.printdocument();设置打印机开始打印的事件处理函数.函数原形如下:voiddoctoprint_printpage(objectsender,system.drawing.printing.printpageeventargse)将事件处理函数添加到printdocument的printpage事件中。doctoprint.printpage+=newprintpageeventhandler(doctoprint_printpage);设置print

3、document的相关属性,如:printdialog1.allowsomepages=true;printdialog1.showhelp=true;把printdialog的document属性设为上面配置好的printdocument的实例:printdialog1.document=doctoprint;调用printdialog的showdialog函数显示打印对话框:dialogresultresult=printdialog1.showdialog();根据用户的选择,开始打印:if(result==dialogresult.ok){

4、doctoprint.print();}例子如下:使用时先创建printservice类的实例,然后调用voidstartprint(streamstreamtoprint,stringstreamtype)函数开始打印。其中streamtoprint是要打印的内容(字节流),streamtype是流的类型(txt表示普通文本,image表示图像);--------------------------------------------------------------------------------usingsystem;usingsyst

5、em.drawing.printing;usingsystem.windows.forms;usingsystem.io;namespaceedimagesystem{///

///printservice的摘要说明。///publicclassprintservice{publicprintservice(){////todo:在此处添加构造函数逻辑//this.doctoprint.printpage+=newprintpageeventhandler(doctoprint_printpage);}//将事件

6、处理函数添加到printdocument的printpage中//declaretheprintdocumentobject.privatesystem.drawing.printing.printdocumentdoctoprint=newsystem.drawing.printing.printdocument();//创建一个printdocument的实例privatesystem.io.streamstreamtoprint;stringstreamtype;//thismethodwillsetpropertiesontheprintd

7、ialogobjectand//thendisplaythedialog.publicvoidstartprint(streamstreamtoprint,stringstreamtype){this.streamtoprint=streamtoprint;this.streamtype=streamtype;//allowtheusertochoosethepagerangeheorshewould//liketoprint.system.windows.forms.printdialogprintdialog1=newprintdialog()

8、;//创建一个printdialog的实例。printdialog1.allowsomepages=true;//show

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。