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
Post a Comment