vb.net - Making a button.click event do two different things -


i'm working on simple vb.net program (just using winforms) , terrible @ ui management. i'd have single button starts process, , have same button stop process.

i'm thinking having main form initiate counter, , click event iterate counter. simple check, , if counter thing , odd thing b.

is there better way, aside using 2 buttons or stop/start radio buttons?

i've done exact thing 1 of 2 ways. can use static variable or toggle text of button.

since button has 2 functions, design requires indicate user. following code assumes button's text set in design mode "start", , code start , stop process in subs startprocess , endprocess.

public sub button1_click(byval sender object, byval e system.eventargs)      if button1.text ="start"             startprocess()             button1.text="end"      else             endprocess()             button1.text="start"      end if end sub 

edit

the above solution fine single-language application developed small number of developers.

to support multiple languages, developers typically assign text literals supporting files or databases. in larger development shops, multiple programmers, using display feature of control flow-control may cause confusion , regression errors. in cass, above technique wouldn't work.

instead, use tag property of button, holds object. typically use boolean, used string make more clear what's going on.

public sub new()     'initialize tag     button1.tag="start" end sub     public sub button1_click(byval sender object, byval e system.eventargs)          if button1.tag.tostring="start"                 startprocess()                 button1.tag="end"          else                 endprocess()                 button1.tag="start"          end if     end sub 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -