33
Controls Part 2

Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

  • Upload
    vuanh

  • View
    221

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Controls Part 2

Page 2: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 3: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Properties of DateTimePicker Format CustomFormat Colors… MaxDate MinDate Value Location Size

Page 4: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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 );

Page 5: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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’

Page 6: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 7: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Timer Control Timer control is used for

performing some tasks periodically.

Time period can be set during development or runtime.

Page 8: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 9: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 10: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 11: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 12: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Properties of GroupBox BackColor ForeColor Text Enabled Visible Name

Page 13: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 14: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Properties of RadioButton BackColor CheckAlign Checked ForeColor Text Enabled Visible

Page 15: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Events of RadioButton Click CheckedChanged

Page 16: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 17: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Exercise

Show the gender of the user in the MessageBox by using the choice seen in RadioButtons

Page 18: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 19: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Properties of CheckBox BackColor CheckAlign Checked CheckState ForeColor Text Enabled Visible

Page 20: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Events of CheckBox Click CheckedChanged

Page 21: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 22: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Exercise

Page 23: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

ListBox Control Allows user to select one or

multiple options between a listed collection of choices.

Page 24: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 25: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Events of ListBox DoubleClick SelectedIndexChanged

Page 26: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 27: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Exercise Show the department that is selected in the

MessageBox.

Page 28: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 29: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Properties of ComboBox DropDownWidth MaxDropDownItems Sorted Items SelectedIndex SelectedItem

.

Page 30: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Fundamental Events of ComboBox SelectedIndexChanged

Page 31: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Exercise Convert ListBox control that we have added

to the Form to a ComboBox control.

Page 32: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

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.

Page 33: Controls Part 2 - endustri.anadolu.edu.tr · DateTimePicker Control Date and time information that is stored in DateTimePicker resides in Valueproperty which is DateTimetype. To set

Exercise