Timer On按钮单击事件 [英] Timer On button Click event

查看:63
本文介绍了Timer On按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有按钮,我想要程序,如果每60秒运行一次,它会点击这个按钮自动

这里是我的按钮代码

i have button that i want program if running every 60 seconds it will click on this button auto
here is my button code

<pre lang="C#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
              }

      private void button1_Click(object sender, EventArgs e)
      {
          WebClient MyWebClient = new WebClient();
          MyWebClient.Credentials = new NetworkCredential(&quot;user&quot;, &quot;****&quot;);
          // Read web page HTML to byte array
          Byte[] PageHTMLBytes;
          if (textBox1.Text != &quot;&quot;)
          {

              PageHTMLBytes = MyWebClient.DownloadData(textBox1.Text);

              // Convert result from byte array to string
              // and display it in TextBox txtPageHTML
              UTF8Encoding oUTF8 = new UTF8Encoding();
              richTextBox1.Text = oUTF8.GetString(PageHTMLBytes);
          }
      }
        
    }
}</pre>

推荐答案

<pre lang="C#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Enabled = true;
            timer1.Interval = 60000;
 
              }
 
       private void timer1_Tick(object sender, EventArgs e)
        {
         button1_Click(null,null);
        }

      private void button1_Click(object sender, EventArgs e)
      {
          WebClient MyWebClient = new WebClient();
          MyWebClient.Credentials = new NetworkCredential(&amp;amp;amp;amp;quot;user&amp;amp;amp;amp;quot;, &amp;amp;amp;amp;quot;****&amp;amp;amp;amp;quot;);
          // Read web page HTML to byte array
          Byte[] PageHTMLBytes;
          if (textBox1.Text != &amp;amp;amp;amp;quot;&amp;amp;amp;amp;quot;)
          {
 
              PageHTMLBytes = MyWebClient.DownloadData(textBox1.Text);
 
              // Convert result from byte array to string
              // and display it in TextBox txtPageHTML
              UTF8Encoding oUTF8 = new UTF8Encoding();
              richTextBox1.Text = oUTF8.GetString(PageHTMLBytes);
          }
      }
        
    }
}&amp;amp;amp;lt;/pre&amp;amp;amp;gt;&amp;amp;lt;/pre&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;/pre&gt;</pre>


这篇关于Timer On按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆