资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb点虐 直接打印文件 vbnet printdocument

高分求解vb点虐 打印的问题

报表打印应该也能实现,但是我觉得你这个用文本打印更简单,将数据输出到txt文件,结果用RichTextBox显示,但是需要简单的排版,调用打印机打印RichTextBox即可的

成都创新互联专注于扎兰屯企业网站建设,成都响应式网站建设公司,商城网站建设。扎兰屯网站建设公司,为扎兰屯等地区提供建站服务。全流程按需开发,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务

排版用tab()、space()、vbcrlf或PrintLine(1)换行,代码类似如下样式

PrintLine(1, TAB(60), "准考证" )

PrintLine(1)

PrintLine(1, "姓名:" xingming Space(3) "准考证号:" cel(1) Space(3) cel(2) Space(3) cel(3))

但是TAB()排版比较规整

打印代码类似如下:

PrintDialog1.Document = PrintDocument1

PrintDocument1.DocumentName = "准考证"

PrintDialog1.AllowSomePages = False

PrintDialog1.ShowHelp = False

PrintDialog1.ShowNetwork = False

PrintDialog1.AllowSelection = False

PrintDialog1.AllowPrintToFile = False

MySReader = New StringReader(RichTextBox1.Text)

stringToPrint = MySReader.ReadToEnd()

PageSetupDialog1.Document = PrintDocument1

PageSetupDialog1.PageSettings.Margins.Bottom = 50

PageSetupDialog1.PageSettings.Margins.Top = 50

PageSetupDialog1.PageSettings.Margins.Left = 50

PageSetupDialog1.PageSettings.Margins.Right = 50

If PageSetupDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings '页面设置

If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then

If PrintDialog1.PrinterSettings.IsValid = True Then

PrintDocument1.Print()

MsgBox("打印完成!" vbCrLf "Print completed!", , "Print hint(打印提示)")

Else

MsgBox("打印失败!打印机不可用。" vbCrLf "Print failed! The printer is not valid.", , "Print hint(打印提示)")

End If

Else

Exit Sub

End If

End If

VS2005如何用VB.NET代码实现打印功能

有个PrintDocument控件,可以实现打印。。。

MSDN原话:

使用 PrintDocument 组件

涉及 PrintDocument 组件的两种主要情况是:

简单的打印作业,如打印单个文本文件。在这种情况下,应将 PrintDocument 组件添加到 Windows 窗体,然后在 PrintPage 事件处理程序中添加打印文件的编程逻辑。 该编程逻辑应以使用 Print 方法打印文档结束。

此方法向打印机发送一个 Graphics 对象,该对象包含在 PrintPageEventArgs 类的 Graphics 属性中。

有关如何使用 PrintDocument 组件打印文本文档的示例,请参见

如何:打印 Windows 窗体中的多页文本文件。

更为复杂的打印作业,如想要重新使用已编写的打印逻辑的情况。

在这种情况下,应从 PrintDocument 组件派生一个新组件,并重写

(请参见 Visual Basic 的 重写或 C# 的 重写) PrintPage 事件。

将 PrintDocument 组件添加到窗体后,它出现在 Windows 窗体设计器底部的栏中

VB.NET怎么实现打印功能啊 呜呜(

利用 printdocument控件

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

PrintDocument1.Print()

End Sub

Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim stringFont As New Font("Arial", 16)

Dim rectDraw As New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)

Dim strFormat As New StringFormat

Dim s As String

s = "print word" '打印的内容

e.Graphics.DrawString(s, stringFont, Brushes.AliceBlue, rectDraw, strFormat)

End Sub


分享题目:vb点虐 直接打印文件 vbnet printdocument
当前链接:http://cdkjz.cn/article/ddcpgoo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220