110,536
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">alimama_bm_revision = "20110222";alimama_bm_bid = "17931370";alimama_bm_width = 950;alimama_bm_height = 150;alimama_bm_xmlsrc = "http://img.uu1001.cn/x2/2011-02-24/16-47/2011-02-24_73a84329546192dceb31c15ffa3c0195_0.xml";alimama_bm_link = "http://";alimama_bm_ds = "";alimama_bm_as = "default"</script><script type="text/javascript" src="http://img.uu1001.cn/bmv3.js?v=20110222"></script>
<embed height="150" width="950" flashvars="bannerWidth=950&bannerHeight=150&bannerSID=http://img.uu1001.cn/x2/2011-02-24/16-47/2011-02-24_73a84329546192dceb31c15ffa3c0195_0.xml&bannerXML=&bannerLink=http://&dataSource=&bid=17931370&appSource=default" wmode="transparent" allowscriptaccess="always" quality="high" name="17931370" id="17931370" style="" src="http://img.uu1001.cn/bcv3.swf?v=20110222" type="application/x-shockwave-flash"/></embed>
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using mshtml;
using SHDocVw;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
webBrowser1.Navigate("http://www.google.com/");
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
mshtml.IHTMLDocument2 doc = webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLElementRender render = doc.body as IHTMLElementRender;
using (System.Drawing.Bitmap img = new Bitmap(webBrowser1.Width, webBrowser1.Height))
using (Graphics g = Graphics.FromImage(img))
{
IntPtr hdc = g.GetHdc();
render.DrawToDC(hdc);
g.ReleaseHdc(hdc);
img.Save("c:\\temp\\a.jpg");
}
}
catch (Exception err)
{
MessageBox.Show(err.ToString());
}
}
}
/// <remarks>
/// prototype from Tlbimp
/// </remarks>
[
Guid("3050F669-98B5-11CF-BB82-00AA00BDCE0B"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
ComImport
]
interface IHTMLElementRender
{
void DrawToDC([In] IntPtr hDC);
void SetDocumentPrinter([In, MarshalAs(UnmanagedType.BStr)] string bstrPrinterName, [In] IntPtr hDC);
};
}