I'm new to programming, I'm trying to use the webbrowser1
to increase the hit counter on a webpage, I can do this manually by clicking on the button to increase the hit counter, what I really wanted to do is make a for(i=0; i < 10 ; i++)
statement to refresh the page 10 times, but then I use the statement like this it only increases the page by one, please see the code below, thanks in advance.
url: http://www.comptechdoc.org/independent/web/cgi/javamanual/javaihit.html
namespace开发者_JAVA百科 click
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < 10; i++)
{
webBrowser1.Refresh();
Application.DoEvents();
}
}
}
}
edit: thank you guys, for all your help and fast replys.
I've tryed the code from here: C# how to wait for a webpage to finish loading before continuing and it seems to work well.
private void button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < 10; i++)
{
webBrowser1.Navigate(url);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
}
}
The goal is not very good, cheating is bad:)
However try recreating webBrowser control.
Try putting this inside your loop:
webBrowser1.Navigate(yourURL);
Both links are very useful for you to solve your problem...
http://www.codeproject.com/KB/custom-controls/EasyHit.aspx
http://www.xdevsoftware.com/blog/post/Hit-Counter-for-ASPNET.aspx
You are refreshing the browser too fast - the hit is only counted when the server gets the request (which takes some time, and the previous request is canceled by next request by then).
namespace click
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < 10; i++)
{
webBrowser1.Refresh();
Thread.Sleep(1000);
Application.DoEvents();
}
}
}
}
Of course you should also consider moral side of what you are doing...
Your question is not clear. anyhow if you want to increase the counter value 10 times in 1 hit, you can do it by incrementing the existing value +10.
in the link you given you can use this code
counter += 10
instead of
++counter
精彩评论