winforms - C# Stop the flow of the program and reset it without restarting -


i writing simple windowsform program radiobuttons, buttons, , customary implemented inputbox.

relevant program logic: click 1 of radiobutons groupbox -> enable button -> clicking button initiates custom inputbox asking 1 value , yes/cancel buttons.

| v 

if yes button clicked -> proceed logic flow

if cancel button clicked -> popup window appears ("your input cancelled, want exit application?") yes/no buttons

    |     v 

if yes button clicked -> exit program

if no button clicked -> apply same logic if reset button clicked, reset whole program without restarting <---------this trying achieve (all relevant methods provided below)

what problem?

when click reset button, applies needed actions , stops, waiting further input. exact result trying achieve when click no button in popup window mentioned above.

however, not case. during debug mode, after clicked no button, goes through entire logic of reset button wanted, but right after that, goes if statement (marked in buttongetworkhours_click method). don't want that, want stop flow after applying logic of reset button , waiting input (radiobutton/button click).

what tried

i have searched through several threads here in , tried implementing several suggestions. results of these suggestions commented out inside inputboxprocedure method. also, looking similar posts, give me right idea. they state impossible without reloading. based on thread, thought implementing variable use checking if reset logic running, seems unnecessarily complicated.

ultimate question:

i saw test executable, know possible, unlike posts , threads saying. can please point me in right direction of how proceed it?

relevant code snippet methods

for sake of saving everyone's time include methods relevant question.

private void buttongetworkhours_click(object sender, eventargs e)   {      if (radiobuttonjobstatusfull.checked)       {         inputboxprocedure("enter total hours worked full time employee week", "40");      }      else if (radiobuttonjobstatuspart.checked)      {         inputboxprocedure("enter total hours worked part time employee week", "30");      }       //if, else if, else, unrelated lines above      if()    //<----------------the logic goes here after going through whole reset button logic      {}      else if()      {}      else()      {}   }  private void buttonreset_click(object sender, eventargs e)   {       //clear radiobutton selections       //set strings empty       //disable several buttons , groupboxes       //hide several labels   }  private void inputboxprocedure(string text, string defaulttext)   {      inputboxresult result = inputbox.show(text, "hours entry", defaulttext, new inputboxvalidatinghandler(inputbox_validating));      if (result.ok)      {         labelhoursworked.text = result.text.trim();      }      else      {         if (messagebox.show("input cancelled. wish quit application?", "input cancelled", messageboxbuttons.yesno, messageboxicon.question, messageboxdefaultbutton.button2) == dialogresult.yes)         {            close();         }         else         {            buttonreset_click(this, new eventargs());            //form fr = new form();            //fr.show();            //this.close();            //application.restart();         }      }   } 

try changing inputboxprocedure this:

private bool inputboxprocedure(string text, string defaulttext) {     inputboxresult result = inputbox.show(text, "hours entry", defaulttext, new inputboxvalidatinghandler(inputbox_validating));     if (result.ok)     {         labelhoursworked.text = result.text.trim();     }     else     {         if (messagebox.show("input cancelled. wish quit application?", "input cancelled", messageboxbuttons.yesno, messageboxicon.question, messageboxdefaultbutton.button2) == dialogresult.yes)         {             close();         }         else         {             buttonreset_click(this, new eventargs());             //form fr = new form();             //fr.show();             //this.close();             //application.restart();              return false; // added         }     }      return true; // added } 

notice return type void becomes bool , 2 lines of return have been added.

in buttongetworkhours_click change:

if (radiobuttonjobstatusfull.checked) {     inputboxprocedure("enter total hours worked full time employee week", "40"); } else if (radiobuttonjobstatuspart.checked) {     inputboxprocedure("enter total hours worked part time employee week", "30"); } 

into:

if (radiobuttonjobstatusfull.checked) {     if (!inputboxprocedure("enter total hours worked full time employee week", "40"))         return; } else if (radiobuttonjobstatuspart.checked) {     if (!inputboxprocedure("enter total hours worked part time employee week", "30"))         return; } 

in way, after reset, funtion inputboxprocedure return false. when function returns false function buttongetworkhours_click return , prevent further excecution.

i hope helps.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -