1、新建工程(MainTest.cs窗体)
2、添加窗体(ChildTest.cs窗体)
3、引用com组件“Microsoft WEB浏览器”
4、分别在两个窗体中添加“浏览器”控件
5、MainTest窗体中写
private void MainTest_Load(object sender, System.EventArgs e)
{
this.IsMdiContainer = true ;//设置成子窗体的容器(父窗体)
System.Object nullobject = 0;
axWebBrowser1.Navigate(" http://www.163.com",ref nullobject,ref nullobject,ref nullobject,ref nullobject); //默认的浏览网址
}
2、添加窗体(ChildTest.cs窗体)
3、引用com组件“Microsoft WEB浏览器”
4、分别在两个窗体中添加“浏览器”控件
5、MainTest窗体中写
private void MainTest_Load(object sender, System.EventArgs e)
{
this.IsMdiContainer = true ;//设置成子窗体的容器(父窗体)
System.Object nullobject = 0;
axWebBrowser1.Navigate(" http://www.163.com",ref nullobject,ref nullobject,ref nullobject,ref nullobject); //默认的浏览网址
}
private void axWebBrowser1_NewWindow2(object sender,AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e)
//用来监控弹出窗体的事件
{
ChildTest newFrmChild = new ChildTest();
newFrmChild.MdiParent = this; // 设为子窗体
newFrmChild.Show(); //显示子窗体
newFrmChild.TopMost = true; //置前
newFrmChild.axWebBrowser1.RegisterAsBrowser = true; //设置获得子窗浏览器信息
e.ppDisp = newFrmChild.axWebBrowser1.Application; //加载弹出窗体的内容到子窗体浏览器
}
6、ChildTest窗体中写
private void ChildTest_Load(object sender, System.EventArgs e)
{
//让浏览器控件添充整个窗体
this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
}
private void axWebBrowser1_WindowSetWidth(object sender, AxSHDocVw.DWebBrowserEvents2_WindowSetWidthEvent e) //根据弹出的窗体宽度来决定子窗 体的宽度
{
int widthDiff;
widthDiff = this.Width - this.axWebBrowser1.Width;
this.Width = widthDiff + e.width;
}
private void axWebBrowser1_WindowSetHeight(object sender, AxSHDocVw.DWebBrowserEvents2_WindowSetHeightEvent e )//根据弹出的窗体高度来决定子窗体的高度
{
int heightDiff;
heightDiff = this.Height - this.axWebBrowser1.Height;
this.Height = heightDiff + e.height;
}
{
ChildTest newFrmChild = new ChildTest();
newFrmChild.MdiParent = this; // 设为子窗体
newFrmChild.Show(); //显示子窗体
newFrmChild.TopMost = true; //置前
newFrmChild.axWebBrowser1.RegisterAsBrowser = true; //设置获得子窗浏览器信息
e.ppDisp = newFrmChild.axWebBrowser1.Application; //加载弹出窗体的内容到子窗体浏览器
}
6、ChildTest窗体中写
private void ChildTest_Load(object sender, System.EventArgs e)
{
//让浏览器控件添充整个窗体
this.axWebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
}
private void axWebBrowser1_WindowSetWidth(object sender, AxSHDocVw.DWebBrowserEvents2_WindowSetWidthEvent e) //根据弹出的窗体宽度来决定子窗 体的宽度
{
int widthDiff;
widthDiff = this.Width - this.axWebBrowser1.Width;
this.Width = widthDiff + e.width;
}
private void axWebBrowser1_WindowSetHeight(object sender, AxSHDocVw.DWebBrowserEvents2_WindowSetHeightEvent e )//根据弹出的窗体高度来决定子窗体的高度
{
int heightDiff;
heightDiff = this.Height - this.axWebBrowser1.Height;
this.Height = heightDiff + e.height;
}
7、总结:本程序还一点就是主浏览器显示的东西总是遮挡弹出窗体的内容。(测试过3721截获不了弹出窗体)