ITeye博客

c#截图

kong0itey · 2012-06-05 00:09 · c# · 编程语言 · Markdown


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace pdf
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length > 0)
            {
                webBrowser1.Navigate(textBox1.Text);
            }
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if(webBrowser1.ReadyState!=WebBrowserReadyState.Complete)
            {
                return;
            }
            HtmlDocument  doc = webBrowser1.Document;
            int height = Convert.ToInt32(doc.Body.GetAttribute("scrollHeight")) + 10;
            int width = Convert.ToInt32(doc.Body.GetAttribute("scrollWidth")) + 10;
            webBrowser1.Height = height;
            webBrowser1.Width = width;
            Bitmap bmp = new Bitmap(width, height);
            Rectangle rec = new Rectangle();
            rec.Width = width;
            rec.Height = height;
            webBrowser1.DrawToBitmap(bmp, rec);
            bmp.Save("d:\\testIta.jpg");
            bmp.Dispose();
        }
    }
}


评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。