รบกวนช่วยหน่อยครับ Set default paper size แล้วมันไม่เป็นตาม size 300*700 ที่กำหนดครับ มันได้ size ออกมาตามภาพครับ
Private Sub PrintDetail()
printdoc = New PrintDocument
printdoc.PrintController = prnpre
printdoc.DefaultPageSettings.PaperSize = New PaperSize("Custom", 300, 700)
printdoc.Print()
End Sub
Private WithEvents prnpre As New Printing.PreviewPrintController()
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
Private Sub Preview_Print(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles printdoc.EndPrint
Dim pre() As Printing.PreviewPageInfo = prnpre.GetPreviewPageInfo()
Dim Folder As String = "D:\OUT\" & Now.ToString("dd.MM.yyyy", dtf) & "\"
Dim Filepath As String = Folder & "Test1.jpg"
For i As Integer = 0 To pre.Length - 1
Call keybd_event(System.Windows.Forms.Keys.Snapshot, 0, 0, 0)
Try
Catch ex As Exception
Exit Sub
End Try
Next
End Sub
Private WithEvents printdoc As PrintDocument
Private Sub printdoc_PrintPage(ByVal sender As Object, ByVal e As Drawing.Printing.PrintPageEventArgs) Handles printdoc.PrintPage
Dim fnt As String = "Courier New"
e.Graphics.Clear(Color.White)
e.Graphics.DrawRectangle(Pens.Black, New Rectangle(2, 0, 280, 60))
e.Graphics.DrawString("TEST PRINT.", New Font(fnt, 10, FontStyle.Bold), Brushes.Black, 5, 5)
End Sub
Tag : .NET, Web (ASP.NET), Win (Windows App), VB.NET