473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 12469
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.