首先说明,这个问题不是很简单,建议各位回答前开下VS写个小程序试一试。form中就一个webBrowser1和一个button.初始设webBrowser的URL为"http://www.baidu.com". 单击button执行以下函数。button_click()
{
   string sites[] = new string[]{"http://www.sina.com.cn", "http://www.sohu.com", "http://www.163.com"};   foreach(string site in sites)
   {
       webBrowser1.Navigate(site);
       Thread.Sleep(5000);  //等待加载
       webBrowser1.GoBack();
   }
}
我的意图是:依次访问sina,sohu,163.可是按照上面的代码,每次都只能访问到163. 哪位大侠可以解决这个问题?

解决方案 »

  1.   

    dropdownlist没有文本输入框框的,我想用层做一个输入框框,我的dropdownlist是动态生成的,这个时候我就要将层移动到dropdownlist上去。请问我怎么获取dropdownlist的坐标值,然后让层覆盖该dropdownlist?
    以下帖子给分。
    如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
    http://community.csdn.net/Expert/topic/5580/5580708.xml?temp=.7489435
    昨天晚上发错连接,更正在发送。
      

  2.   

    考虑用WebBrowser.DocumentCompleted 事件
      

  3.   

    WebBrowser.DocumentCompleted 不行
      

  4.   

    string[] sites = new string[] { "http://www.sina.com.cn", "http://www.163.com", "http://www.sohu.com" };
            int c = -1;
     //文档加载完成
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                //MessageBox.Show("加载完成");
                webBrowser1.GoBack();
                button1_Click(null, null);
            }        
            private void button1_Click(object sender, EventArgs e)
            {
                c++;
                webBrowser1.Navigate(sites[c]);
                
            }
    =================================================
    这样做不可行,打开一个sina主页,webBrowser1_DocumentCompleted就执行几十次了
      

  5.   

    string[] sites = new string[] { "http://www.sina.com.cn", "http://www.163.com", "http://www.sohu.com" };
    int c = -1;
    //文档加载完成
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
    //MessageBox.Show("加载完成");
    webBrowser1.GoBack();
    button1_Click(null, null);
    }
    private void button1_Click(object sender, EventArgs e)
    {
    timer1.Enabled =true; } private void timer1_Tick(object sender, EventArgs e)
    {
    c++;
    if(c < sites.Length)
    {
    webBrowser1.Navigate(sites[c]);
    }
    else
    {
    c = -1;
    }
    }
      

  6.   

    partial class Form1
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.IContainer components = null; /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
    protected override void Dispose(bool disposing)
    {
    if(disposing && (components != null))
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    } #region Windows 窗体设计器生成的代码 /// <summary>
    /// 设计器支持所需的方法 - 不要
    /// 使用代码编辑器修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();
    this.button1 = new System.Windows.Forms.Button();
    this.timer1 = new System.Windows.Forms.Timer(this.components);
    this.webBrowser1 = new System.Windows.Forms.WebBrowser();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(96, 188);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(75, 23);
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.UseVisualStyleBackColor = true;
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // timer1
    // 
    this.timer1.Enabled = true;
    this.timer1.Interval = 10000;
    this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
    // 
    // webBrowser1
    // 
    this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.webBrowser1.Location = new System.Drawing.Point(0, 0);
    this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
    this.webBrowser1.Name = "webBrowser1";
    this.webBrowser1.Size = new System.Drawing.Size(292, 266);
    this.webBrowser1.TabIndex = 1;
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.button1);
    this.Controls.Add(this.webBrowser1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.WebBrowser webBrowser1; }