VB中的Printer.Print在.Net中如何实现
在VB中,如果要打印打印A4文档,且内容是从DB中,或者DataGrid中等动态获取的,实现起来非常简单,诸如以下代码(rs表示一记录集):
rs.MoveFirst
Printer.PaperSize = VBPRPSA4
Printer.Orientation = VBPRORPortrait
Printer.FontName = "Courier New"
Printer.FontBold = True
Printer.FontSize = 24
Printer.Print " FQA Report"
Printer.FontSize = 16
Printer.Print " Pallet ID:" & Trim(rs("pallet_id"))
NewLine2 = String(100, " ")
Mid(NewLine2, 1, 5) = "NO#"
Mid(NewLine2, 10, 30) = "System S/N"
Mid(NewLine2, 35, 20) = "BOX_ID"
Mid(NewLine2, 60, 20) = "Pallet_ID"
While Not rs.EOF
NewLine2 = String(100, " ")
Mid(NewLine2, 1, 5) = Trim(rs("No"))
Mid(NewLine2, 10, 30) = Trim(rs("SN"))
Mid(NewLine2, 35, 20) = Trim(rs("BOX_ID"))
Mid(NewLine2, 60, 20) = "" & Trim(rs("Pallet_ID"))
Printer.Print NewLine2
rs.MoveNext
Wend
Printer.Print NewLine2
Printer.Print String(100, "-")
在上述代码中,如果记录集中的数量很多,即内容超出了一页纸,程序不用做任何设置,便会自动分页,那么到.Net中,如何实现这么一个简单的功能呢?
查了好多资料,上网搜了好久,发现没有类似的例子,看了MSDN后,才发现,到VB.Net中,VB中那么好用的Printer不见了,一下为MSDN的描述:http://msdn.microsoft.com/zh-tw/library/cc438273(VS.71).ASPx
"Visual Basic 6.0 中的 Printer 物件在 Visual Basic .NET 中是由 PrintDocument 组件取代。两者的行为不同,但在多数情况下可复制功能。下表将列出 Visual Basic 6.0 属性 (Property)、方法及事件与其 Visual Basic .NET 对等用法。如果没有直接的对等用法,则会提供连结以取得其它信息。除非另外注明,否则所有的对象都是在 System.Drawing 命名空间中。"
第一感觉是,在.Net中有比这更好用的打印功能,而且功能更强大,于是开始翻
3465


&spm=1001.2101.3001.11974&articleId=5559480&d=1&t=3&u=76bbbe4135fd40a58cc0c02589579b4e)

被折叠的 条评论
为什么被折叠?



