1 / 8

Lecture Set 5

Lecture Set 5. Control Structures Part C – Groups of Controls. Objectives. Learn first how to construct grouped controls with statically defined choices

Télécharger la présentation

Lecture Set 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.


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

More Related