Download presentation
Presentation is loading. Please wait.
1
Control Structures Part C – Groups of Controls
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 2/24/ :58 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 2/24/ :58 PM2/24/ :58 PM
4
The GroupBox Control (Syntax)
The BackColor and ForeColor properties define the color Visual text appears in the Text property 2/24/ :58 PM2/24/ :58 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 2/24/ :58 PM2/24/ :58 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 2/24/ :58 PM2/24/ :58 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); int rowID = (int)thisID[0] - (int)'0'; int colID = (int)thisID[1] - (int)'0'; ((Button)sender).Enabled = false; ((Button)sender).Text = "C"; } // end Button Click 2/24/ :58 PM2/24/ :58 PM
8
Multi-cast Event Handlers (Another Example)
For more examples, look at Lecture Set 07, particularly: LectureSet07XSender LectureSet07XDynamic 2/24/ :58 PM2/24/ :58 PM
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.