winforms - Show and Hide a label in windows forms continuously -


i want show , hide label continuously (using sleep in loop). here doing:

for (i = 0; < 25; i++) {       label1.visible = true;       thread.sleep(1000);       label1.visible = false;       thread.sleep(2000); } 

however, above code not working expected. don't see label @ all. idea how achieve this

using thread.sleep freezes windows of youre interface must run separated tread or use timer example:

    void blinklabel()     {         int blink_times = 25;          system.windows.forms.timer timer1 = new system.windows.forms.timer();                      timer1.interval = 1000;//every 1 second          timer1.tick += new system.eventhandler((s, e) =>         {             if (blink_times >= 0)             {                 label1.visible = !label1.visible;                 blink_times--;             }             else             {                 timer1.stop();             }         }         );           timer1.start();     }    

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -