Hack Forums
[C#] Making a button clickable every 10 seconds. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Making a button clickable every 10 seconds. (/showthread.php?tid=4567288)

Pages: Pages 1 2


* - Corios - Dec 3, 2014

(Dec 3, 2014 04:08 PM)Old_Horse Wrote:  Oops, my bad. That's what you get for not reading the specs 🤦‍♂

ya, it was written slightly weird. I mean it's not far off and it I agree with a timer in this case, but ya that would need to be fixed :P


* - Sicarius - Dec 3, 2014

Have the button set to Unclickable (not sure what the exact method is called, believe it is Enabled();) then when the timer is done have it set to be click able again.


* - SL x TnT - Dec 3, 2014

I haven't really worked with async that much, so someone can correct this if anything's wrong.

Guessing you may want to do this with more controls. This should be easier than creating a new thread for each.

PHP Code

<?php 
private void button1_Click(object sender, EventArgs e)
      {
      
DisableControl(sender as Button, 5000);
      }

      private 
void button2_Click(object sender, EventArgs e)
      {
      
DisableControl(sender as Button, 2000);
      }

      private 
async void DisableControl(Control con, int delay)
      {
      if (
con != null)
      {
      
con.Enabled = false;
      
await Task.Delay(delay);
      
con.Enabled = true;
      }
      }