c# - Implementing nested If-cycles in a winform -


for example have nested if-cycle in console like

if (answer == "one") {     console.writeline("one or two?");     string answer = console.readline();      if (answer == "one")     {         console.writeline("pressed1");     }     else          console.writeline("pressed2")     //....and on } 

everything works fine. if try same in winform, turns out pressing button1 i nested results marked "btn1".so getting "pressed 1 pressed 1". how can make program stop same way stops in console console.readline()?

if (btn.name == "btn1") {     richtextbox1.appendtext("pressed1");     if (btn.name == "btn1")     {         richtextbox1.appendtext("pressed1");     }     else (btn.name == "btn2")     {         richtextbox1.appendtext("pressed2");     } 

the posted code fragment isn't full, it's easy speculate confusion is.

basically, console application being processed in sequential order, blocking calls input injected flow.

on winform application on other hand, flow event based. there no predetermined sequence of events, , no blocking calls.

your console code inspects value of answer variable in outer if , waits new input user further processing. winform code inspects btn.name, appends text text box, , immediately moves on next if statement. if want stop sequence, return event handler, , continue flow in different event handler.

a note potential -1's: yes, know console application can event based, doesn't have sequential in nature , on. answer supposed op understand logic & problem.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -