Private Sub btn_print_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_print.Click
If PrintDialog2.ShowDialog = DialogResult.OK Then
PrintDocument2.OriginAtMargins = True
PrintDialog2.Document = PrintDocument2
PrintDocument2.Print()
End If
End Sub
Private Sub PrintDocument2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim mybitmap = New Bitmap(pic_sup.Width, pic_sup.Height)
pic_sup.DrawToBitmap(mybitmap, New Rectangle(0, 0, pic_sup.Width, pic_sup.Height))
e.Graphics.DrawImage(mybitmap, 100, 100)
mybitmap.Dispose()
End Sub
รูปภาพจาก PictureBox ครับ
รูปที่ปริ้นได้มาครับ
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2008 (.NET 3.x), VS 2010 (.NET 4.x)
Private Sub PrintDocument2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument2.DefaultPageSettings
intPrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
intPrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left ' X coordinate
marginTop = .Margins.Top ' Y coordinate
End With
Dim mybitmap = New Bitmap(pic_sup.Width, pic_sup.Height)
pic_sup.DrawToBitmap(mybitmap, New Rectangle(marginLeft, marginTop, intPrintAreaWidth, intPrintAreaHeight))
e.Graphics.DrawImage(mybitmap, 0, 0)
mybitmap.Dispose()
End Sub