首先说明,这个问题不是很简单,建议各位回答前开下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. 哪位大侠可以解决这个问题?
{
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. 哪位大侠可以解决这个问题?
解决方案 »
- 为什么把ViewStat重新赋值以后无效呢
- 返回页面时刷新出现错误请高手解决下!谢谢!
- html与aspx
- 如何将excel中的数据导入到dataset中?
- WinForm,如何显示数据库中的二进制文件
- 如何隐藏DataGrid的第一行??
- 怎么通过gacutil.exe将一个程序集放入全局程序集缓存。报告错误:Attemp to install an assembly without a strong name.怎么样解决??
- 如何把新的DLL发个每个客户端,而且客户端在使用,谁帮帮我
- 0分贴抗议!抗议CSDN推出完全不知所谓的"显示星级回复"这种巨搞笑的功能。
- 用“|”间隔是什么意思?
- CheckedListBox怎样根据Item内容自动调整多列的列宽ColumnWidth
- C#如何自动执行click事件
以下帖子给分。
如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
http://community.csdn.net/Expert/topic/5580/5580708.xml?temp=.7489435
昨天晚上发错连接,更正在发送。
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就执行几十次了
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;
}
}
{
/// <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; }