Could someone please share the code to take screenshots of web browser control and save it in predetermined path.
I am working with VS 2008 .Net 3.5 .
You could use Control.DrawToBitmap(), even though it is hidden from Intellisense in VisualStudio. The WebBrowser still inherits from the base class Control, so this method does exist. But what I did was create a MenuStrip with a MenuItem that I used to test this (this is basically just a standard click-event), and instead created a graphics object, and copied a portion of the screen using the correct cordinates. The only things you will need to adjust really, is the name of the WebBrowser control, and the line that actually saves the image.
private void copyToolStripMenuItem_Click(object sender, EventArgs e) {
int width, height;
width = webBrowser1.ClientRectangle.Width;
height = webBrowser1.ClientRectangle.Height;
using (Bitmap image = new Bitmap(width, height)) {
using (Graphics graphics = Graphics.FromImage(image)) {
Point p, upperLeftSource, upperLeftDestination;
p = new Point(0, 0);
upperLeftSource = webBrowser1.PointToScreen(p);
upperLeftDestination = new Point(0, 0);
Size blockRegionSize = webBrowser1.ClientRectangle.Size;
graphics.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize);
}
image.Save("C:\\Test.bmp");
}
}
Here's an article illustrating this. And there's another. And even more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With