`
kong0itey
  • 浏览: 299444 次
社区版块
存档分类
最新评论

c#截图

    博客分类:
  • c#
 
阅读更多
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();
        }
    }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics