10
Controls in C++/CLI (2) • CheckBox • RadioButton • GroupBox • ListBox

Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

Embed Size (px)

Citation preview

Page 1: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

Controls in C++/CLI (2)• CheckBox

• RadioButton

• GroupBox

• ListBox

Page 2: 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

Page 3: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

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

Page 4: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

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

Page 5: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

Controls in C++/CLI (2)

• GroupBox – Group RadioButtons, will allow multiple in a

form -- each in one group

Page 6: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

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)

Page 7: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

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

Page 8: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

• 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

Page 9: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

An Example (1)

• Draft a design….

• Form1 and myDialog Classes – Variables, methods– Components, event handlers– Collections

Page 10: Controls in C++/CLI (2) CheckBox RadioButton GroupBox ListBox

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;