先添加2个COM对象引用来控制IE浏览器
Microsoft HTML Object Library
Microsoft Internet Controls
代码如下:
/// <summary>
/// 获取IE浏览器的内容
/// </summary>
void shellwindow()
{
SHDocVw.ShellWindows shellwindows = new SHDocVw.ShellWindows();
string fileName;
foreach (SHDocVw.InternetExplorer ie in shellwindows)
{
fileName = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (fileName.Equals("iexplore"))
{
this.txtWebAddress.Text = ie.LocationURL;//获取URL地址
mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;//HTML内容
break;
}
}
}