There are three primary button controls—conventional click event buttons, radio buttons, and check box buttons—as pictured in Figure 6.13:
The Button control. Buttons are used to signal that a particular action should now occur. In Figure 6.13, we provide three buttons: OK, Clear, and Quit. The primary Button event is a user's click. For example,
protected void button1_Click( object sender, EventArgs e ) { int cnt = 0; // figure out which images were selected for ( int ix = 0; ix < imageSet.Count; ++ix ) if ( imageSet[ ix ] ) { image += imageTitle[ ix ]; cnt++; } // make sure all necessary items were selected if ( payment == null || format == null || cnt == 0 ) { string msg = "Please Select Photo(s), Format, and Payment"; MessageBox.Show( msg ); Clear(); return; } string message = "You chose " + cnt + " images for " + format + " to be paid through " + payment; label2.Text = message + " " + image; }
The RadioButton control. Radio buttons are used primarily for mutually exclusive selection. When the user selects one radio button within a group, the others clear automatically. In Figure 6.13 we provide two groups of radio buttons: Format and Payment. We design this setup in two steps: First we drop a GroupBox control into the form; second, we drop each RadioButton control into the group box. The primary radio button event is CheckChanged, which occurs whenever the checked status of the button changes. For example, here is our event handler for one of the radio buttons:
protected void radioButton7_CheckedChanged( object sender, EventArgs e ) { if ( radioButton7.Checked ) format = radioButton7.Text; }
Checked is the property that indicates whether the button has been selected. To clear a selection, we set that property to false. format is a string member introduced to hold the selection.
The CheckBox control. Check boxes are used to support multiple selections. In Figure 6.13 we provide a panel of four check boxes; the user can select any combination of the four. As with the RadioButton control, the primary check box event is CheckChanged, which occurs whenever the checked status of the box changes. In the following example, imageSet is a BitArray class object used to keep track of which images the user has selected:
protected void checkBox4_CheckedChanged( object sender, EventArgs e ) { // Anna with Dog imageSet[ 0 ] = checkBox4.Checked ? true : false; }
3.143.22.23