C # create a web refresh Tool

Source: Internet
Author: User

The web page refresh tool, as its name implies, is used to refresh webpages, which can greatly improve your popularity. The famous web page refresh tool on the internet includes the Huayu automatic refresh tool ,(Http://hnny.skycn.com/down/hy2008b.zip). After using the timer, it seems that the interface is not easy to understand. In fact, the principle is very simple. It is to use the timer control to regularly execute events and open or refresh the webpage, in case of jokes, let's publish them first!

 

 

 

First, add the control as shown in the figure above, and name the control according to certain naming rules. In fact, there are two hidden controls, one is the timer control (used to set events on a scheduled basis), and the other is the tooltip control (used to prompt related user information). After the interface is configured, write the code!

 

First, let the program get the focus as soon as it loads the address bar. Remember, here you can set the tab attribute of the address bar for control, but the difference between C # and VB is: instead of focusing a widget in a load event, you must write it in the form shown event.

Private void form1_shown (Object sender, eventargs E)
{
Cboxurl. Focus ();
}

 

To ensure the proper running of the program, we must also perform some tests, such as checking whether the website is correct and whether the time interval meets the requirements, to prevent unexpected exit of the program. Of course, you can also use the try --- catch statement.

// Check whether the URL and interval are correct
Private bool check ()
{
If (cboxurl. Text = "")
{
MessageBox. Show ("Enter the URL to be refreshed", "prompt", messageboxbuttons. OK, messageboxicon. information );
Cboxurl. Focus ();
Return false;
}
If (txtTime. Text = "" | Convert. ToSingle (txtTime. Text) <= 0)
{
MessageBox. Show ("enter the correct time interval", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Information );
TxtTime. Text = "";
TxtTime. Focus ();
Return false;
}
Return true;
}

 

Next, click the code for the start button. Here I use two forms: refresh and convert to form. I have tried it, some web pages must be refreshed to increase the access volume, and some must be switched.

 

Private void btnOk_Click (object sender, EventArgs e)
{
Try
{
If (check ())
{
If (btnOk. Text = "Start refreshing ")
{
String url = cboxUrl. Text. Trim ();
WebMain. Navigate (url); // load the webpage
// If (webMain. IsBusy = true)
//{
// GbWeb. Text = "loading webpage ";
//}
// Else
//{
// Gbweb. Text = webmain. Document. title;
//}
Timer1.interval = convert. toint32 (convert. tosingle (txttime. Text) * 1000 );
Timer1.start ();
Btnok. Text = "stop refreshing ";
GbSet. Enabled = false;
GbModle. Enabled = false;
}
Else
{
Timer1.Stop ();
BtnOk. Text = "Start refreshing ";
LabNum. Text = "0 ";
GbSet. Enabled = true;
GbModle. Enabled = true;
}
}
}
Catch (exception ex)
{
MessageBox. Show (ex. message, "error", messageboxbuttons. OK, messageboxicon. Error );
Return;
}
}

 

The following are the events of the key Timer control.

Private void timereffectick (object sender, EventArgs e)
{
String url = cboxUrl. Text. Trim ();
If (rbtnF5.Checked = true)
{
WebMain. Refresh (); // Refresh the webpage
}
Else
{
WebMain. Navigate (url); // go to the webpage
}

LabNum. Text = Convert. ToString (Convert. ToInt32 (labNum. Text) + 1 );
}

 

Okay! This is the end of the process. But can you add more items? Yes. For example, if I don't want him to display it in the taskbar during running, we can narrow down the tray.

 

Private void Form1_SizeChanged (object sender, EventArgs e)
{
If (this. WindowState = FormWindowState. Minimized)
{
This. ShowInTaskbar = false;
This. policyicon1.visible = true;
}
}

 

So how can we restore it? It's not easy. Just double-click the event!

 

Private void policyicon#doubleclick (object sender, EventArgs e)
{
This. WindowState = FormWindowState. Normal;
This. ShowInTaskbar = true;
This. policyicon1.visible = false;
}

 

OK. There are some other modifiers in the source code. Please download

If you think this series of articles is good and you need to continue writing them, please leave a message to encourage them!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.