【问题标题】:How to make axMozillaBrowser control wait berofe it navigates another web-page如何让 Mozilla 浏览器控件在浏览另一个网页之前等待
【发布时间】: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


【解决方案1】:

您的浏览器控件是否有导航(或类似的)事件? 例如,您可以在简单的逻辑循环中使用它,您的控件导航到集合中的第一个 URL,然后,当导航完成时,导航到第二个 URL 和下一个。

upd:抱歉,我又读了一遍,现在看不懂。 upd2: 但我建议你找到 Navigated 和 Navigating 事件以及 NavigationState 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 2013-02-15
    相关资源
    最近更新 更多