【发布时间】:2012-08-28 15:51:00
【问题描述】:
我正在创建一个简单的网络浏览器重新加载程序。在我的程序中,我正在使用这些控件
axMozillaBrowser,
Button,
progressBar,
TextBox
我正在尝试将网页加载“5”次。下面是我使用 webBrowser 控件(Internet Explorer 的一个实例)时可以使用的代码
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
while (progressBar1.Value !=5 )
{
webBrowser1.Navigate(textBox1.Text);
while(webBrowser1.ReadyState != webBrowserRedyState.Complete)
{
if (webBrowser1.ReadyState == webBrowserRedyState.Complete)
{
progressBar1.Value =+ 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 5;
textBox1.Text = "www.google.com";
}
}
}
这是在我使用 axMozillaBrowser 控件(Mozilla 浏览器的一个实例)时不起作用的代码。这不会加载网页,它的等待光标只是闪烁。
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
while (progressBar1.Value !=5 )
{
axMozillaBrowser1.Navigate(textBox1.Text);
while(axMozillaBrowser1.ReadyState != MOZILLACONTROLLib.tagREADYSTATE.READYSTATE_COMPLETE)
{
if (axMozillaBrowser1.ReadyState == MOZILLACONTROLLib.tagREADYSTATE.READYSTATE_COMPLETE)
{
progressBar1.Value =+ 1;
}
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Maximum = 5;
textBox1.Text = "www.google.com";
}
}
}
【问题讨论】:
-
如果我不执行等待,那么它将无法正确加载页面,它将进行第二次导航,然后是第三次和第四次。这就是为什么我希望它等到它完成第一次导航之后去下一个
-
请告诉我我需要做什么才能让 axMozillaBrowser 控件等到它完成第一次导航然后再进行下一次导航
标签: c# .net webbrowser-control mozilla