c# - Moving on with points using check boxes and if statement -


i'm creating c# quiz using windows forms on visual studio. question "what average beats per minute healthy male , female teenage student?" possible answers 4 check boxes user must select 2 answers. there button user hits when have selected answers , moves them onto next form. how use if statement validate user has selected 2 answers(not correct one) before moving on. user must have selected 2 answers before can move on or message box show ensuring know pick two. struggling fill brackets after word if. many thanks!

private void btnnextquestion_click(object sender, eventargs e)     {        if ()         {             messagebox.show("please select 2 answers.");         }         else         {             this.hide();             frmquestionfour frm = new frmquestionfour();             frm.show();  

you need this:

int count = 0; if (chk1.checked) count++; if (chk2.checked) count++; if (chk3.checked) count++; if (chk4.checked) count++; if (count == 2) 

if have placed checkbox references collection can use linq this:

if (checkboxes.where(chk => chk.checked).count() == 2) 

and if 4 checkboxes only checkboxes on screen try this:

if (controls.oftype<checkbox>().where(chk => chk.checked).count() == 2) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -