Click here to Skip to main content
15,896,606 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 169K   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.Runtime.InteropServices;
using System.IO;
using System.Drawing.Printing;

namespace DEMO
{
    public partial class Form1 : Form
    {
        private MyButton button2;
        PrintDocument pd = null;
        StreamReader STreamToPrint = null;
        public Form1()
        {
            InitializeComponent();
            //button2 = new MyButton();
            //button2.Location = new System.Drawing.Point(196, 164);
            //button2.Name = "button2";
            //button2.Size = new System.Drawing.Size(75, 23);
            //button2.TabIndex = 0;
            //button2.Text = "button2";
            //button2.UseVisualStyleBackColor = true;
            ////button2.Click += new System.EventHandler(this.button1_Click);
            //this.Controls.Add(this.button2);
       
         
        }
       

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int MessageBox(System.IntPtr hWnd, string text, string caption, uint type);
        
        private void button1_Click(object sender, EventArgs e)
        {
            if (tbUrl.Text.Equals(string.Empty)) return;
            webBrowser1.Url = new Uri(tbUrl.Text);
          drawing=new Bitmap(600,800);
          webBrowser1.DrawToBitmap(drawing,new Rectangle(webBrowser1.Location.X,webBrowser1.Location.Y,webBrowser1.Width,webBrowser1.Height));
          Graphics g = pBrowser.CreateGraphics();
          
          int width = drawing.Width;
          int height = drawing.Height;
          RectangleF destinationRect = new RectangleF(
              10,
              20,
              0.3f * width,
              0.3f * height);

          RectangleF sourceRect = new RectangleF(0, 0,  width, height);
         g.DrawImage(
              drawing,
              destinationRect,
              sourceRect,
              GraphicsUnit.Pixel);


            //MessageBox(System.IntPtr.Zero, "hello", "caption text", 0);
        }
        Bitmap drawing = null;

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

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