Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > vb.net > december 2005 >

vb.net : Control.DrawToBitmap and Restrictions


powella NO[at]SPAM gmail.com
12/14/2005 9:40:04 AM
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.
powella NO[at]SPAM gmail.com
12/14/2005 11:00:16 AM
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.
powella NO[at]SPAM gmail.com
12/14/2005 12:22:37 PM
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.
Herfried K. Wagner [MVP]
12/14/2005 7:36:06 PM
<powella@gmail.com> schrieb:
[quoted text, click to view]

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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
Herfried K. Wagner [MVP]
12/14/2005 8:03:24 PM
<powella@gmail.com> schrieb:
[quoted text, click to view]


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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Herfried K. Wagner [MVP]
12/14/2005 10:12:47 PM
<powella@gmail.com> schrieb:
[quoted text, click to view]

Thanks in advance.

[quoted text, click to view]

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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
powella NO[at]SPAM gmail.com
12/15/2005 6:44:23 AM
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.
AddThis Social Bookmark Button