Click here to Skip to main content
15,903,744 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have button that i want program if running every 60 seconds it will click on this button auto
here is my button code
C#
<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>
Posted
Comments
Sergey Alexandrovich Kryukov 13-Jan-16 2:47am    
Why doing such nasty things?
—SA
GTR0123 13-Jan-16 3:18am    
i have local server witch have programed website and i need it
Ralf Meier 13-Jan-16 3:26am    
Do you really want to simulate a Button-Click ...?
Or could it be enough to call the same functions / method as in the Button-Click-method every Minute ?
If you say Yes to my Suggestion then you only need to intergrate a Timer and call with it's Tick-Event the needed functions/methods.
GTR0123 13-Jan-16 3:32am    
i want tthat this timer call this button event
Richard MacCutchan 13-Jan-16 3:42am    
Create a separate method with the functionality you want. you then call that method from your timer and your button click event.

1 solution

C#
<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>
 
Share this answer
 
Comments
Maciej Los 15-Jan-16 15:20pm    
Few words of explanation would be great!
yourfriendaks 21-Jan-16 2:44am    
i initialized timer with interval of 60 seconds.so tick event will fire after every 60 seconds where i am calling your button click event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900