VB.net中实现打印窗体

前端之家收集整理的这篇文章主要介绍了VB.net中实现打印窗体前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

示例
Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (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 System.Int32) As Long
Dim memoryImage As Bitmap
Private Sub CaptureScreen()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.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,Me.ClientRectangle.Width,_
Me.ClientRectangle.Height,dc1,13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object,_
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
PrintDocument1.PrintPage
e.Graphics.DrawImage(memoryImage,0)
End Sub
Private Sub PrintButton_Click(ByVal sender As System.Object,ByVal e As _
System.EventArgs) Handles PrintButton.Click
CaptureScreen()
PrintDocument1.Print()
End Sub
编译代码
此示例需要:

窗体上名为 PrintDocument1 的 PrintDocument 组件。 名为 PrintButton 的 Button 控件。在单击 PrintButton 时,就会打印该窗体。

原文链接:https://www.f2er.com/vb/264190.html

猜你在找的VB相关文章