Solution for PrintForm in .NET
Hello!
I just found a code snippet that is capable of getting control image even when the control is invisible or overlapped by others :D
So forget about BitBlt problems :cool:
Code:
Private Function GetControlBitmap(ByVal CTL As Control) As Bitmap
Dim Methods() As System.Reflection.MethodInfo = ctl.GetType.GetMethods( _
System.Reflection.BindingFlags.Instance Or _
System.Reflection.BindingFlags.NonPublic)
Dim i As Integer
Dim OnPaintMethod As System.Reflection.MethodInfo
For i = 0 To Methods.Length - 1
If Methods(i).Name = "OnPaint" Then
OnPaintMethod = Methods(i)
Exit For
End If
Next
If Not OnPaintMethod Is Nothing Then
Dim _BMP As New Bitmap(CTL.Width, CTL.Height)
Dim _Gr As Graphics = Graphics.FromImage(_BMP)
Dim PaintEventArgs As New System.Windows.Forms.PaintEventArgs(_Gr, _
New Rectangle(0, 0, CTL.Width, CTL.Height))
OnPaintMethod.Invoke(ctl, New Object() {PaintEventArgs})
_Gr.Dispose()
Return _BMP
End If
End Function
Originally posted in MS VB.NET newsgroup by Craig Vick :wave: