|
#Region " Form drucken "
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
Private Const SRCCOPY As Integer = &HCC0020
Dim memoryImage As Bitmap
Private Sub CaptureForm()
Dim mygraphics As Graphics = Me.CreateGraphics()
Dim sz As Size = Me.Size
memoryImage = New Bitmap(sz.Width, sz.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, Me.ClientRectangle.Width, _
Me.ClientRectangle.Height, dc1, 0, 0, SRCCOPY)
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, 0)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
CaptureForm()
PrintDocument1.Print()
End Sub
#End Region
|
|