Dim memoryImage
Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Int32) As Boolean
'======ปุ่มปริ้น
Private Sub btnPrintpreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintpreview.Click
'dlgEmpOnline.Visible = False
CaptureScreen()
'lgEmpOnline.Visible = True
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
'=========Sub แคปเจอร์===========
Private Sub CaptureScreen()
Dim mygraphics As Graphics = Panel4.CreateGraphics() ' ---- เปลี่ยนเป็น GroupBox1.CreateGraphics()
Dim s As Size = Panel4.Size ' ---- เปลี่ยนเป็น GroupBox1.Size
memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, Panel4.ClientRectangle.Width, Panel4.ClientRectangle.Height, dc1, 0, 0, 13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub
'========Printpage===================
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawImage(memoryImage, 10, 10)
End Sub