0
我有一個有一些控件的組框,並且我想將它發送給打印機。如何將羣組內容的內容發送到打印機
我有這個代碼即構建從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
睜開了眼睛。有用的鏈接。在問題區發佈最終工作代碼。 –