VB.Net - DateTimePicker Control

The DateTimePicker control allows you to display and collect date and time from the user with a specified format.

vb.net-datetimepicker.jpg

The DateTimePicker control prompts the user for a date or time using a graphical calendar with scroll arrows. The most important property of the DateTimePicker is the Value property, which holds the selected date and time.

DateTimePicker1.Value = "12/31/2010"

 

The Value property is set to the current date by default. You can use the Text property or the appropriate

member of Value to get the date and time value.

Dim idate As String

idate = DateTimePicker1.Value

 

The control can display one of several styles, depending on its property values. The values can be displayed in four

formats, which are set by the Format property: Long, Short, Time, or Custom.

DateTimePicker1.Format = DateTimePickerFormat.Short

 

The following VB.Net program shows how to set and get the value of a DateTimePicker1 control.

 

Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		DateTimePicker1.Format = DateTimePickerFormat.Short
		DateTimePicker1.Value = "12/31/2010"
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim idate As String
		idate = DateTimePicker1.Value
		MsgBox("Selected date is  : " & idate)
	End Sub

End Class
Next Post Previous Post
No Comment
Add Comment
comment url