vb.net 如何在 .net 中打印文本文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4763029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:14:25  来源:igfitidea点击:

How do I print a text file in .net

vb.netprinting

提问by Connor Albright

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

如何在 vb.net 中打印 .txt 文件?希望不使用任何第三方。

回答by Justin Grant

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

请参阅如何在 vb.net 中打印批处理文件?. 有一个 VB.NET 代码示例,您应该可以逐字使用。

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

如果您还不知道如何从文件中提取文本,请使用File.ReadAllText,如下所示:

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

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

RawPrinterHelper是上面链接的另一个问题中描述的类。“WindowsPrinterName”是您要打印到的打印机的名称。

回答by Tim Schmelter

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

查看有关如何使用 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.

您需要的最重要的类是PrintDocument。除了 .Net-Framework(> 1.1) 中的 System.Drawing 和 System.IO Namespace 之外,不需要第三方工具或 Dll。