How do I print a text file in .net

此生再无相见时 提交于 2019-12-22 13:57:19

问题


How do I print a .txt file in vb.net? Hopefully without using any third parties.


回答1:


Have a look at this example on how to print files with VB.Net: MSDN How to: Print a Multi-Page Text File in Windows Forms

The most important class you need is PrintDocument. No third party tools or Dll's other than in System.Drawing and System.IO Namespace in .Net-Framework(> 1.1) are needed.




回答2:


See How to print batch file in vb.net?. There's a VB.NET code sample which you should be able to use verbatim.

If you don't already know how to pull text out of a file, use File.ReadAllText, like this:

Imports System.IO
Dim path As String = "c:\temp\MyTest.txt"
RawPrinterHelper.SendStringToPrinter("WindowsPrinterName", File.ReadAllText(path)) 

RawPrinterHelper is the class described in the other question linked above. "WindowsPrinterName" is the name of the printer you want to print to.



来源:https://stackoverflow.com/questions/4763029/how-do-i-print-a-text-file-in-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!