loops - C# Make Program Wait For Button To Be Pressed -


i want make program wait button pressed before continues, tried creating while loop , having loop until button clicked , sets bool true while loop end, made crash

   while (!redpress)                     {                         //i'd wait here                     }                     redpress = false; 

it doesn't matter whether or not while there, long program waits button press before setting "redpress" false... ideas?

use events - it's they're designed for.

you don't need use boolean variable in button_click event handler call code:

private void button_click(object sender, eventargs e) {     // code need execute when button pressed } 

as @trickdev points out need subscribe event if use events window in visual studio add necessary code - including empty handler - you.

with event driven programs waiting until next "thing" happens. in case (if i've understood application correctly) when start program should tell first button flash "n" times. if write event application return waiting state once code has completed.

then in button click event handler - can subscribe buttons same event - can check correct button has been pressed , tell next button flash. if wrong button pressed display suitable message.

so in pseudo code have:

public class form {     initialise()     {         this.loaded += formloaded;     }      private void formloaded(object sender, eventargs e)     {         // pick button         pickedbutton.flash();     }      private void button_click(object sender, eventargs e)     {         if (sender == pickedbutton)         {             pickedbutton = pickbutton();         }         else         {             message = "sorry wrong button, try again";         }          pickedbutton.flash();     } }  public class button {     public void flash()     {         // loop n times turning button on/off     } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -