Hi VBP,
I was assuming that you'd followed the link that Herfried had given and
got the code for the alternate method.
It 'manually' triggers the OnPaint event for the target Control but passes
in the Graphics context of <your> Bitmap rather than that of the Control. So
the Control is fooled into drawing itself directly onto the Bitmap. There's a
block of code which uses Reflection to find the OnPaint method. My snippet was
just a replacement for that as it does more than is needed.
As I mentioned in my previous post, it works and doesn't work, depending.
It's definitely worth trying out. To save you the hassle, here it is.
Regards,
Fergus
<code>
Public Function PaintControlToBitmap (oControl As Control) As Bitmap
Dim OnPaintMethod As MethodInfo
OnPaintMethod = oControl.GetType.GetMethod ("OnPaint", _
BindingFlags.Instance Or BindingFlags.NonPublic)
If Not OnPaintMethod Is Nothing Then
Dim bmpControl As New Bitmap (oControl.Width, oControl.Height)
Dim gr As Graphics = Graphics.FromImage (bmpControl)
Dim PaintEventArgs As New PaintEventArgs (gr, _
New Rectangle(0, 0, oControl.Width, oControl.Height))
OnPaintMethod.Invoke (oControl, New Object() {PaintEventArgs})
gr.Dispose
Return bmpControl
End If
End Function
</code>