直接从 VB.NET 打印到点阵打印机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14023239/
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-17 11:40:51  来源:igfitidea点击:

Print to a Dot-Matrix Printer directly from VB.NET

vb.netprintingepsondot-matrix

提问by Panos B.

i am finishing a program i am writing and i have to create a printing to an Epson LQ-300+ Dot-Matrix. The printing has to print some text in some specific parts of the paper (Amount,name etc) Can anyone point me to the right direction or post me an example since i was not able to find something in order to send directly the ASCII characters to the printer via LPT1. Thank you.

我正在完成我正在编写的程序,我必须打印到 Epson LQ-300+ 点阵。打印必须在纸张的某些特定部分(数量、名称等)打印一些文本,任何人都可以指出我正确的方向或发布一个示例,因为我无法找到某些内容以便将 ASCII 字符直接发送到打印机通过 LPT1。谢谢你。

采纳答案by Mark Hall

IT Is going to be mainly trial and error a far as positioning goes, it is also going to depend on the font and wether or not you are using a Generic/Text Driver (if so the character spacing, line spacing and font are what ever the printer has been setup for). Back in the DOS days you could send out individual characters to the printer but printing in windows is page based meaning you will need to use the PrintDocument Class, handle the PrintPage eventusing the PrintPageEventArgsGraphic Property'sPrintString Methodto position the text where you need it to be.

就定位而言,它主要是反复试验,它还将取决于字体以及您是否使用通用/文本驱动程序(如果是这样,字符间距、行间距和字体是什么打印机已设置为)。回到 DOS 时代,您可以向打印机发送单个字符,但在 Windows 中打印是基于页面的,这意味着您需要使用PrintDocument 类, 使用PrintPageEventArgs图形属性的PrintString 方法处理PrintPage 事件以将文本定位在您需要的位置成为。

Something like this:

像这样的东西:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
        PrintDocument1.Print()
    End If
End Sub

Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    e.Graphics.DrawString("Hello World", New Font("Arial", 10), Brushes.Black, New Point(100, 100))
End Sub