Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

Webpage thumbnailer

Rate me:
Please Sign up or sign in to vote.
4.75/5 (25 votes)
17 Aug 20062 min read 168.5K   6K   98  
An article on how to get a webpage thumbnail and give your favorite links a face.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace net.grool.util
{
	public partial class BrowserForm : Form
	{
		public BrowserForm()
		{
			InitializeComponent();

			webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

		}
		PicDoc picDoc = null;

		public PicDoc CurDoc
		{
			get { return picDoc; }
			set { picDoc = value; }
		}
		/// <summary>
		/// This method calls starts download of the page .
		/// </summary>
		/// <param name="url"></param>
		public void getImageFromUrl(string url)
		{

			try
			{
				this.webBrowser1.Url = new Uri(url);

			}
			catch (Exception ex)
			{

				MessageBox.Show(ex.Message);

			}



		}
		/// <summary>
		/// This event handler is called after document is loaded in browser.
		/// We copy content of the invisible browser to new bitmap and pass it to PicDoc object which in turn will fire refreshPicture event.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void webBrowser1_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
		{

			try
			{

				Bitmap docImage = new Bitmap(600, 800);
				webBrowser1.DrawToBitmap(docImage, new Rectangle(webBrowser1.Location.X, webBrowser1.Location.Y, webBrowser1.Width, webBrowser1.Height));
				this.picDoc.Image = this.picDoc.getSizedImage(docImage);

			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}


		}

		

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions