473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Taking a Screenshot of a WebBrowser on a Tab

Hello group,

I have a project with several WebBrowser objects on separate tabs. I
want to take screenshots of these. I am currently using the
PrintWindow function. (Code below.) This works if the tab is open and
the WebBrowser is displayed. For browsers on other tabs, however, the
resulting bitmap is black.

Any ideas on how to tweak this code so that it snapshots WebBrowsers
on tabs that are not selected? Or should I be using a different method
altogether?

Thank you,

J Wolfgang Goerlich
The C# code ...

[DllImport("user32.dll")]
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt,
uint nFlags);

private void BrowserSnapShot(System.Windows.Forms.WebBrowser
targetBrowser)
{
// Get the image width and height

int screenWidth = targetBrowser.Width;
int screenHeight = targetBrowser.Height;

// Create the output

// HWND hwnd, Window to copy
// HDC hdcBlt, HDC to print into
// UINT nFlags, Optional flags

// Set hwnd to the WebBrowser

IntPtr myIntptr = targetBrowser.Handle;
int hwndInt = myIntptr.ToInt32();
IntPtr hwnd = myIntptr;

// Set hdc to the bitmap

Bitmap bm = new Bitmap(screenWidth, screenHeight,
System.Drawing.Imaging.PixelFormat.Format16bppRgb5 55);
Graphics g = Graphics.FromImage(bm);
IntPtr hdc = g.GetHdc();

// Snapshot the WebBrowser

bool result = PrintWindow(hwnd, hdc, 0);
g.ReleaseHdc(hdc);
g.Flush();

// Save the bitmap, if successful

if (result == true)
bm.Save("C:\\Inetpub\\wwwroot\\slide.bmp");

}

Feb 20 '07 #1
4 12481
On Feb 20, 9:20 pm, jwgoerl...@gmail.com wrote:
Hello group,

I have a project with several WebBrowser objects on separate tabs. I
want to take screenshots of these. I am currently using the
PrintWindow function. (Code below.) This works if the tab is open and
the WebBrowser is displayed. For browsers on other tabs, however, the
resulting bitmap is black.

Any ideas on how to tweak this code so that it snapshots WebBrowsers
on tabs that are not selected? Or should I be using a different method
altogether?
Did you try to use WebBrowser.DrawToBitmap()?

As far as I know it does the same and you can use it for all your
WebBrowser objects in the same time

Feb 20 '07 #2
Did you try to use WebBrowser.DrawToBitmap()?

Is there something special needed to enable this? Visual Studio 2005
reports that "this method is not supported by this control."

J Wolfgang Goerlich

Feb 20 '07 #3
On Feb 20, 11:12 pm, jwgoerl...@gmail.com wrote:
Did you try to use WebBrowser.DrawToBitmap()?

Is there something special needed to enable this? Visual Studio 2005
reports that "this method is not supported by this control."

J Wolfgang Goerlich
F1 :-)

Namespace: System.Windows.Forms

I found that you use C:\\Inetpub\\wwwroot\\

Does it mean you do it in ASP.NET? If yes, take a look this tip at
http://www.codeproject.com/useritems...screenshot.asp

Feb 20 '07 #4
F1 :-)

Good ol' help. Though not supported, it does work just as detailed in
the ASP.NET article (thanks!).

"DrawToBitmap - This method is not supported by this control.
(inherited from WebBrowserBase)"
http://msdn2.microsoft.com/en-us/lib...r_members.aspx

And yet, the DrawToBitmap acts the same as the PrintWindow. It creates
a good snapshot if the tab with the WebBrowser is selected. It creates
a black, blank bitmap if the tab is not selected. Looks like I may
have to settle for selecting the tab with the WebBrowser, creating the
bitmap, and then going back to the originally selected tab.

J Wolfgang Goerlich

Feb 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3106
by: SPE - Stani's Python Editor | last post by:
Hi, During optimizing SPE for Ubuntu, I found something strange. I have Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not working: >>> import webbrowser >>>...
1
1307
by: Li-fan Chen | last post by:
Hi, In creating an email client, we are trying to allow users to pick and choose their email templates and photo stocks. We thought it'd be very 2006 to show a gallery of thumbnails. Is this a...
12
6331
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
4
2292
by: dananrg | last post by:
Is there a Python module that, given a URL, will grab a screenshot of the web page it goes to? I'd like to be able to feed such a module a list of URLs from a file. Thanks very much.
11
2799
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
19
4562
by: mareeus | last post by:
Hi, Are there any ways I could get a screenshot of a web-page at a specific address in jpeg via php script? Regards, Marius.
1
1516
by: phpfreak2007 | last post by:
Hello, I want screenshot of website by passing url. I used the DrawtoBitmap method of webbrowser but it is not working properly. It gives empty images. I want screenshot of websites which i...
11
2190
by: kimiraikkonen | last post by:
Hi there, I needed to use MouseOver event on Webbrowser which is NOT provided by webbrowser control natively(what a disappointment), so i decided to go with another route to simulate this like: ...
3
9419
by: TedTrippin | last post by:
Hi, Background - I've create a windows application in VS and added a WebBrowser component and all works well. I'm now trying to do this programmatically. My application now listens on a socket...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.