DateTimePicker Control in VB.Net
A DateTimePicker control allows you to select a date and time.
Drag and drop DateTimePicker control form toolbox on window Form.

Code:
' DateTimePicker ValueChanged
Event Hander
Private
Sub DateTimePicker1_ValueChanged(ByVal sender As
System.Object, ByVal e
As System.EventArgs) Handles
DateTimePicker1.ValueChanged
'Display the selected Date in Label
Label2.Text = DateTimePicker1.Text
End Sub
Run the project

When you click on the calendar icon in the control then calendar popup will
show.

When you select the date then ValueChanged event will fire and selected date
will be show in Label.

DateTimePicker Properties:
Format:
we can set DateTimePicker Format in which Format it should show.
Private
Sub Form2_Load(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
MyBase.Load
'Display the date in Short Format
DateTimePicker1.Format = DateTimePickerFormat.Short
End Sub
At run time DateTimePicker value will
show in short Format.

Show
checkbox:
You can make a DateTimePicker control editable where you can change the value
without using the Calendar. This can be done by setting ShowCheckBox property to
true.
Private Sub
Form2_Load(ByVal sender
As System.Object, ByVal e
As System.EventArgs)
Handles MyBase.Load
' Makes DateTimePicker editable
DateTimePicker1.ShowCheckBox = True
End Sub

Checkbox will show in DateTimePicker.You can edit the value in DateTimePicker and changed
value will show in Label.
ShowUpDown
We can also use an up-down control to set the date and time.
Private
Sub Form2_Load(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
MyBase.Load
'UpDown control will show in DateTimePicker
DateTimePicker1.ShowUpDown = True
End Sub

UpDown Control is display in
DateTimePicker.we can change date through Updown.
|