Home > DeveloperSection > Articles > DateTimePicker Control in VB.Net

DateTimePicker Control in VB.Net

Posted by  Pushpendra Singh
on    December-14-2010 21:20 PM

VB.Net VB.Net 
Ratings:
0 Comment(s)
 15437  View(s)
Rate this:

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.

DateTimePicker Control in VB.Net

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

DateTimePicker Control in VB.Net

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

DateTimePicker Control in VB.Net

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

DateTimePicker Control in VB.Net

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.

DateTimePicker Control in VB.Net

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

DateTimePicker Control in VB.Net

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

DateTimePicker Control in VB.Net

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
















Recent Activities


Kamlakar Singh added new Blog Convert Text Document to PDF File   11 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   11 days ago

Kamlakar Singh added new Question Explain the AdRotator Control.   12 days ago

Don't want to miss updates? Please click the below button!