473,652 Members | 3,162 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("user 32.dll")]
private static extern bool PrintWindow(Int Ptr hwnd, IntPtr hdcBlt,
uint nFlags);

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

int screenWidth = targetBrowser.W idth;
int screenHeight = targetBrowser.H eight;

// 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.H andle;
int hwndInt = myIntptr.ToInt3 2();
IntPtr hwnd = myIntptr;

// Set hdc to the bitmap

Bitmap bm = new Bitmap(screenWi dth, screenHeight,
System.Drawing. Imaging.PixelFo rmat.Format16bp pRgb555);
Graphics g = Graphics.FromIm age(bm);
IntPtr hdc = g.GetHdc();

// Snapshot the WebBrowser

bool result = PrintWindow(hwn d, hdc, 0);
g.ReleaseHdc(hd c);
g.Flush();

// Save the bitmap, if successful

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

}

Feb 20 '07 #1
4 12489
On Feb 20, 9:20 pm, jwgoerl...@gmai l.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.Draw ToBitmap()?

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.Draw ToBitmap()?

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...@gmai l.com wrote:
Did you try to use WebBrowser.Draw ToBitmap()?

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\\ww wroot\\

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!).

"DrawToBitm ap - 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
3111
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 >>> webbrowser.open("http://www.python.org") It does not throw an exception, but is not able to launch a browser.
1
1318
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 quick .NET Framework call in 2.0 or 1.1? Here are the requirements in my mind: * Max width and Max height configurable. * As well rendered as possible when shrinking. Let us set quality. I'll do the shrinking myself, that's okay.
12
6357
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 of course it's thrown up a whole host of new issues... I'm generating a multi page printable document in HTML from my app, and displaying it in a WebBrowser control. I've looked into using some CSS
4
2299
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
2817
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
4577
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
1534
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 passed in loop. arrayList arrURL; bool flagSC = true; for(int i=0l i< url.length;i++) { if (flagSC == true)
11
2207
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: //////////////////////////////////////////////// Public Sub DisplayHyperlinks(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs)
3
9434
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 and when it receives a request it creates a new Form and adds a new WebBrowser. The problem - All works well without the WebBrowser, the form is visible, but when I do "Controls.Add(webBrowser)" I see nothing, not even something in the windows...
0
8367
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8279
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.