Upload
vuanh
View
221
Download
0
Embed Size (px)
Citation preview
Controls Part 2
DateTimePicker Control Used for representing
Date/Time information and take it as input from user.
Date information is automatically created.
Prevents wrong date and time input.
Fundamental Properties of DateTimePicker Format CustomFormat Colors… MaxDate MinDate Value Location Size
DateTimePicker Control Date and time information that is stored in
DateTimePicker resides in Value property which is DateTime type.
To set Value property first we should create a new DateTime object; public DateTime( int year, int month, int day ); public DateTime( int year, int month, int day, int
hour, int minute, int second );
DateTimePicker Control To return value as string; We use DateTimePicker.Value.ToString(string format)
function. Possible format input types Year : ‘y’ Month : ‘M’ Day : ‘d’ Hour : ‘h’ Minute : ‘m’ Second : ‘s’
Exercise Previously we created a form which takes
user’s name and surname. Now add a DateTimePicker control to the form. Then show user’s birth date in the MessageBox.
Timer Control Timer control is used for
performing some tasks periodically.
Time period can be set during development or runtime.
Timer Properties Enabled Interval
Note : Timer can not be seen on the form. It runs at background and performs it’s action when determined time is passed.
Exercise Add time property to our program. To accomplish this add a Timer control
named timerClock to Form. Then set Intervalproperty to 1000 msec = 1sec and Enabledproperty to true.
Add a Label to form and set it’s name to lblHour.
Open Events view and create Tick Event Handler for Timer.
Exercise Add the code to timerClock_Tick function that
will write current to lblHour. Note: To obtain current time you may use
DateTime.Now.Tostring() function.
GroupBox Used for grouping a bunch of
elements that are logically related with each other.
Creates sub-sets of elements on the form depending on their functionalities.
Relations between of some the controls (e.g. RadioButtons) are automatically assigned when they reside in the same group.
Fundamental Properties of GroupBox BackColor ForeColor Text Enabled Visible Name
RadioButton Control Enables user to select a single
option from a group of choices. Only one RadioButton can be in
selected state within a form or GroupBox.
Fundamental Properties of RadioButton BackColor CheckAlign Checked ForeColor Text Enabled Visible
Fundamental Events of RadioButton Click CheckedChanged
Exercise Add a functionality to the form that asks user
about his/her gender. In this task create a GroupBox named
grpGender and set its Text property to “Gender”.
Add two RadioButtons (rbMale and rbFemale) to the GroupBox and set appropriate texts to the radio buttons.
Change Checked property of one of the RadioButton to true.
Exercise
Show the gender of the user in the MessageBox by using the choice seen in RadioButtons
CheckBox Control It is similar to the RadioButton but
all CheckBoxes can be selected in a CheckBox group.
In other words, CheckBoxes are used when user can select multiple options between multiple choices.
Fundamental Properties of CheckBox BackColor CheckAlign Checked CheckState ForeColor Text Enabled Visible
Fundamental Events of CheckBox Click CheckedChanged
Exercise Create a GroupBox named grpLectures and
place at least four CheckBoxes that holds lecture names.
Depending of the check state of these CheckBoxes write the lectures to the MessageBox which are selected by user.
Exercise
ListBox Control Allows user to select one or
multiple options between a listed collection of choices.
Fundamental Properties of ListBox SelectionMode Sorted Items SelectedIndex SelectedItem
Note : To add items to a ListBox; You should call Items.Add() function during run-time or Add lines to the window which is opened when Items
element is clicked in Properties during design time.
Fundamental Events of ListBox DoubleClick SelectedIndexChanged
Exercise Add a ListBox named lbDepartment to the
Form. And add a couple of departments the the window which is opened when Items property is clicked.
Exercise Show the department that is selected in the
MessageBox.
ComboBox Control Enables user to select only one
option between a listed collection.
During selection all items in the collection are displayed but, after selection only selected item is displayed.
Fundamental Properties of ComboBox DropDownWidth MaxDropDownItems Sorted Items SelectedIndex SelectedItem
.
Fundamental Events of ComboBox SelectedIndexChanged
Exercise Convert ListBox control that we have added
to the Form to a ComboBox control.
Exercise Write a program that calculates the bills in a
restaurant. Program first should ask table number and
customer name. Then dishes should be selected from menu
and added to the bill. Finally account of invoice is calculated after processing discounts.
Exercise