Lec10 - Lecture 10: Radio Buttons & Windows PIC 10C Todd...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 10: Radio Buttons PIC 10C Todd Wittman b The Check Box control gets a yes/no response from the user. b We can check the boolean Checked property of the control. if (iceCreamBox.Checked) foodLabel.Text = "You like ice cream."; else foodLabel.Text = "What??? You don't like ice cream???"; b The Radio Button control is similar. b The key difference is that Radio Buttons are mutually exclusive , which means you can only check one in the group.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Grouping Radio Buttons b Suppose we lay out 5 radio buttons. b The problem with this is that we can only select one of the 5 choices. We really should set up 2 groups: parents and children. b The Group Box control is simply a rectangle that you place related controls on. b Placing the last 3 radio buttons on a group box says they are in a different set than the 2 radio buttons on the form itself. b In each group set 1 button to be checked initially, usually the first on the list. Radio Button Example private string favParent, favChild; private void enterButton_Click(object sender, EventArgs e) { if (margeRadio.Checked) favParent = "Marge"; else if (homerRadio.Checked) favParent = "Homer"; if (lisaRadio.Checked) favChild = "Lisa"; else if (bartRadio.Checked) favChild = "Bart"; else if (maggieRadio.Checked) favChild = "Maggie"; MessageBox.Show("Your favorites are "+favParent+" and "+favChild+"."); }
Background image of page 2
3 Writing Our Own Event b The else-if statements are rather annoying, especially since we
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/18/2010 for the course PIC 10C taught by Professor Wittman during the Spring '10 term at UCLA.

Page1 / 7

Lec10 - Lecture 10: Radio Buttons & Windows PIC 10C Todd...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online