몇 가지 컨트롤이있는 그룹 상자가있어서 프린터로 보내려고합니다.groupbox의 내용을 프린터로 보내는 방법
이 코드는 groupbox에서 bmp 파일을 작성합니다. 버튼 클릭시 어떻게 프린터로 보낼 수 있습니까?
Private Sub Doc_PrintPage(sender As Object, e As PrintPageEventArgs)
Dim x As Single = e.MarginBounds.Left
Dim y As Single = e.MarginBounds.Top
Dim bmp As New Bitmap(Me.GroupBox1.Width, Me.GroupBox1.Height)
Me.GroupBox1.DrawToBitmap(bmp, New Rectangle(0, 0, Me.GroupBox1.Width, Me.GroupBox1.Height))
e.Graphics.DrawImage(DirectCast(bmp, Image), x, y)
End Sub
내가 버튼을 클릭 이벤트에 있습니다 조언 후
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim doc As New PrintDocument()
doc = Doc_PrintPage()
Dim dlgSettings As New PrintDialog()
dlgSettings.Document = doc
If dlgSettings.ShowDialog() = DialogResult.OK Then
doc.Print()
End If
End Sub
최종 작업 코드 :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BMP = New Bitmap(GroupBox1.Width, GroupBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
GroupBox1.DrawToBitmap(BMP, New Rectangle(0, 0, GroupBox1.Width, GroupBox1.Height))
Dim pd As New PrintDocument
Dim pdialog As New PrintDialog
AddHandler pd.PrintPage, (Sub(s, args)
args.Graphics.DrawImage(BMP, 0, 0)
args.HasMorePages = False
End Sub)
pdialog.ShowDialog()
pd.PrinterSettings.PrinterName = pdialog.PrinterSettings.PrinterName
pd.Print()
End Sub
내 눈이 열렸습니다. 유용한 링크. 질문 영역에 게시 된 최종 작업 코드. –