Download
lecture set 5 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture Set 5 PowerPoint Presentation
Download Presentation
Lecture Set 5

Lecture Set 5

152 Vues Download Presentation
Télécharger la présentation

Lecture Set 5

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lecture Set 5 Control Structures Part C – Groups of Controls

  2. Objectives • Learn first how to construct grouped controls with statically defined choices • (Later – not in this Lecture Set) Learn at least one way to populate a grouped control from a dynamically changeable source such as a simple sequential file or even a database 1/3/2016 8:49 PM

  3. Control Groups • Container controls are used to group control instances together • The GroupBox control is a container control • Visual Studio supports several other container controls 1/3/2016 8:49 PM

  4. The GroupBox Control (Syntax) • The BackColor and ForeColor properties define the color • Visual text appears in the Text property 1/3/2016 8:49 PM

  5. The RadioButton Control • The end user selects one button from a group of buttons • Members • The Text property contains the visible text • The Checked property defines whether the RadioButton is selected • The CheckedChanged event fires when the button is clicked 1/3/2016 8:49 PM

  6. Multicast Event Handlers (Introduction) • One event handler handles the same event for many control instances • The Handles clause contains a comma-separated list of control instances and event names • A period separates the control instance and event name 1/3/2016 8:49 PM

  7. Multicast Event Handlers (Example) • Handles click event for all 9 buttons on Tic-Tac-Toe board • Uses name (“btnrc”) attribute of button where r is the row ID and c the column ID of the button (0 <= r, c <= 2) // “Wires” event handler to each of 9 buttons (part of nested loops) this.boardView[row, col].Click += new System.EventHandler(this.Button_Click); // One event handler wired to all 9 buttons on the board private void Button_Click(object sender, EventArgs e) { Button thisButton = (Button)sender; thisButton.BackColor = Color.LightGoldenrodYellow; string thisID = thisButton.Name.Substring(3, 2); introwID = (int)thisID[0] - (int)'0'; intcolID = (int)thisID[1] - (int)'0'; ((Button)sender).Enabled = false; ((Button)sender).Text = "C"; } // end Button Click 1/3/2016 8:49 PM

  8. Multi-cast Event Handlers (Another Example) • For more examples, look at Lecture Set 07, particularly: LectureSet07XSender LectureSet07XDynamic 1/3/2016 8:49 PM