To Display and Read Value from DatePicker in dd.yyyy.mm (VB.net code)

Rajnilari2015
Posted by Rajnilari2015 under Windows Forms category on | Points: 40 | Views : 766
The below code (in VB.net) will help us to Display and Read Value from DatePicker in dd.yyyy.mm.

Imports System.Windows.Forms

Namespace WindowsFormsApplication1
Public Partial Class Form1
Inherits Form
Private format As String = "dd.yyyy.MM"
'date format
Public Sub New()
InitializeComponent()
End Sub

'set the datepicker display format at form load time
Private Sub Form1_Load(sender As Object, e As EventArgs)
dateTimePicker1.Format = DateTimePickerFormat.[Custom]
dateTimePicker1.CustomFormat = format

End Sub

'read the datepicker value of the given format on button click
Private Sub button1_Click(sender As Object, e As EventArgs)
MessageBox.Show(dateTimePicker1.Value.[Date].ToString(format))
End Sub
End Class
End Namespace


For setting the datetime-picker value, we are using

a) Format Property : Gets or sets the format of the date and time displayed in the control.
b) CustomFormat Property : Gets or sets the custom date/time format string.

For reading the value from the datetime-picker, we are formatting the ToString() e.g.
ToString(format)

Comments or Responses

Login to post response