กำหนดชื่อเครื่องพิมพ์ในโค้ดแล้ว แต่เวลาสั่งพิมพ์ มันออกเครื่องพิมพ์ที่เราต้อง default ของ Windows ครับ
และมีการกำหนดให้ใช้กระดาษขนาดที่ตั้งใน Server Printer
Dim i As Integer
Dim doctoprint As New System.Drawing.Printing.PrintDocument()
doctoprint.PrinterSettings.PrinterName = pntName
For i = 0 To doctoprint.PrinterSettings.PaperSizes.Count - 1
If doctoprint.PrinterSettings.PaperSizes(i).PaperName = "BCS" Then
rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(i).GetType().GetField("kind", Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(i)))
Exit For
End If
Next
r.PrintOptions.PaperSize = CType(rawKind, CrystalDecisions.Shared.PaperSize)
r.PrintOptions.PaperOrientation = PaperOrientation.Portrait
r.PrintOptions.PrinterName = pntName
r.PrintToPrinter(1, False, 1, 1)
r.Dispose()
r.Close()
Tag : .NET, Crystal Report, Win (Windows App), VB.NET, VS 2012 (.NET 4.x), Windows
Dim pd As New PrintDocument
AddHandler pd.PrintPage, AddressOf pd_PrintPage
' Specify the printer to use
pd.PrinterSettings.PrinterName = Printer-Name
' Set the page orientation to landscape.
pd.DefaultPageSettings.Landscape = True
pd.Print()
Imports System.Drawing.Printing
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each PrinterName In PrinterSettings.InstalledPrinters
cmbPrinter.Items.Add(PrinterName)
Next
End Sub
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
Dim rp As New rpTest
rp.PrintOptions.PrinterName = cmbPrinter.Text
rp.PrintToPrinter(1, False, 0, 0)
End Sub
End Class