Upload
buddy-cameron
View
224
Download
5
Embed Size (px)
Citation preview
Controls in C++/CLI (2)• CheckBox
• RadioButton
• GroupBox
• ListBox
Controls in C++/CLI (2)• CheckBox (Property: Text, Checked, CheckState
(checked/unchecked/indeterminate) ; Event: Clicked, CheckedChanged, CheckStateChanged)– Multiple choices
• RadioButton (Property: Text, Checked; Event: Clicked, CheckedChanged)– Single choice in one container
Example 1• Start from the last project TestCheck
– Remove TextBox
• CheckBox Dialog Box:
– Add three CheckBoxes for CS415, CS425, CS435; Names to be cbCS415, cbCS425, cbCS435
– Add variables for inputs, and constructor
– Handle Click events to get input
Form1:
– Invoke dialog box
– Get/use data
Example 2• Start from the last project TestCheck
– Remove TextBox
• RadioButton: Dialog Box: – Add four RadioButtons for Freshman, Sophomore, Junior,
and Senior; Names to be rbFreshman, rbSophomore, rbJunior, and rbSenior
– Add variables for inputs, and constructor – Handle Click events to get input
Form1: – Invoke dialog box– Get/use data
Controls in C++/CLI (2)
• GroupBox – Group RadioButtons, will allow multiple in a
form -- each in one group
Example 3• Start from the Dialog example
• GroupBox: Dialog Box: –Add two GroupBoxes for “years in school” and “study habits”; change the Text And Name accordingly, e.g, Names to be gbYears and gbStudy; – Add RadioBottuns to each GroupBox: “years in school” to have Freshman, Sophomore, Junior, and Senior; and “study habits” to have night owl and early bird; change the Text And Name accordingly;–Add variables for inputs, and constructor –Handle Click events to get input
Form1: –Invoke dialog box; Get/use data (more data and displays)
Controls in C++/CLI (3)• ListBox (Property: SelectionMode, Items,
SelectedItem, SelectedIndex, SelectedItems, SelectedIndices; Event: SelectedIndexChanged)– Show a collection of values, each with index,
scrollable;
– Select one or more items, event
• SelectionMode (None, One, MultiSimple, and MultiExtended) – please see
http://msdn.microsoft.com/en-us/library/system.windows.forms.selectionmode.aspx
• Items (ObjectCollection, add, remove, )• SelectedIndex (Int32, zero-based index) • SelectedIndices (a collection of zero-based indices); • SelectedItem (nullptr value if not actually selected), • SelectedItems• Event: SelectedIndexChanged
An Example (1)
• Draft a design….
• Form1 and myDialog Classes – Variables, methods– Components, event handlers– Collections
An Example (2)• Start from Form1
– Add Label, Text “Name:”, Name “label1”
– Add ListBox, Name “nameList”, SelectionMode “one”;
– Add three Buttons for “Add”, “Delete” and Edit”; Name bnAdd, bnDelete, bnEdit; add click event handlers, bnAdd_Click, bnDelete_Click, bnEdit_Click;
• Add a form for MyDialog
– Add Label, Text “Enter Name:”; Add TextBox, Name myTextBox;
– Add two buttons for “OK” and “Cancel”, Name as bnOK, bnCancel; add click events of bnOK_Click and bnCancel_Click; Write handler methods; set DialogResult for each;
– Set MyDialog’s AcceptButton and CancelButton;