Control.DrawToBitmap and Restrictions

  • Thread starter Thread starter powella
  • Start date Start date
P

powella

Hello All,

I've recently discovered the DrawToBitmap method hidden away in the
Control class (in .NET 2.0). What a fantastic addition to the class.

I'm having some degree of difficulty using it though with controls
other than the Textbox. I would appreciate any information (other than
what is available in the MSDN docs about DrawToBitmap, as I've already
read it) that could be provided about this method and/or how to use it
properly.
 
I've recently discovered the DrawToBitmap method hidden away in the
Control class (in .NET 2.0). What a fantastic addition to the class.

I am curious what doesn't work...

\\\
Private Function CreateScreenshot( _
ByVal Control As Control _
) As Bitmap
Dim Screenshot As New Bitmap(Control.Width, Control.Height)
Control.DrawToBitmap( _
Screenshot, _
New Rectangle(0, 0, Control.Width, Control.Height) _
)
Return Screenshot
End Function
///
 
Interesting. I was going off of an msdn example where the example was
using the Control.Bounds property straight up within DrawToBitmap.
Seems that going that route is incorrect. Thanks for your working
example, I appreciate it.
 
Interesting. I was going off of an msdn example where the example was
using the Control.Bounds property straight up within DrawToBitmap.
Seems that going that route is incorrect. Thanks for your working
example, I appreciate it.


Could you post the URL/help topic name where you found the incorrect sample?
I'll then file a bug report if it's really a bug in the documentation.
 
Will do. I'll have to fish through a sea of browser history, so it may
take a day or so for me to get to it.

Have you, or anyone, attempted to use this on the WebBrowser control.
In the sample app that I'm playing with, I have a picture box's Image
property being set to the return value of your CreateScreenshot method.
I then have a timer running to push visual updates of the control to
the picture box. Now, I can get the image initial 'navigation', but
subsquent navigations result only in a white rect. That is to say that
I can retrieve the image of the WebBrowser control during, and once, it
has navigated to the initial page. However, if I click a link within
the page, the next call(s) to DrawToBitmap return a solid colored rect
within the bitmap.
 
Will do. I'll have to fish through a sea of browser history, so it may
take a day or so for me to get to it.

Thanks in advance.
Have you, or anyone, attempted to use this on the WebBrowser control.

Yes, I have tested it with the webbrowser control on my machine (Windows XP
Professional SP2, .NET 2.0 RTM) and it just works fine, even after
navigating to another site through code, but it didn't work after navigating
by clicking a link. A user in the German language C# group reported that
taking a screenshot of a webbrowser control using 'DrawToBitmap' didn't work
for him at all. According to the documentation this method is not supported
for the webbrowser control.
 
Indeed. I've been peeking at the messages sent to the various windows
in the child-stack for that control to see if there is a message I can
force on it to redraw to whatever dc DrawToBitmap is using. I'll post
an update on my status should I make any progress.
 
Back
Top