ARTICLE

How to use DateTimePicker control in VB.NET

Posted by Dea Saddler Articles | ASP.NET using VB.NET March 22, 2011
In this article you will learn what is DateTimePicker control,its property and how to use it.
Download Files:
 
Reader Level:


A visual basic DateTimePicker Control offers a best way for users to make a date time selection. The date time control drives from the System.Windows.Forms.Control class. This control consist a label which shows the date and a calender by which you can select the new date. The windows forms DateTimePicker control Gives you flexibility in formatting the display of Date and time in control. You can set the date time format by the format property of the DateTimePicker control.
 

Properties of DateTimePicker Control:-

  • Text:- A string object that represents the selected date. 
  • Format:- Format property specify if the format is short or long the default format is long. 
  • MaxDateTime:- Shows MaximumDate supported by Control. 
  • MinDateTime:- Shows MinimumDate supported by Control.

How to use the DateTimePicker Control in VB.NET
  • Create a new project 
  • Drag a DateTimePicker control, one TextBox, three Buttons and a NotifyIcon on form, the form will look like below.

    DateTimePicker1.gif

    DateTimePicker1.1gif.gif

     
  • Write the below code behind the Button1 click, Button2 click, Button3 click.

    Private
    Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
           
    Button1.Click
            Dim obj As New DateTime()
            Dim str As String
            obj = DateTimePicker1.Value
            str = obj.ToString()
            textBox1.Text = str
        End
    Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
           
    Button2.Click
            DateTimePicker1.Hide()
            MessageBox.Show("control hide")
        End Sub
    Private
    Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
           
    Button3.Click
            DateTimePicker1.Show()
            MessageBox.Show("control show")
        End
    Sub
     
  • Then write the code on form load.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Text = "DateTimePicker Control"
            NotifyIcon1.Visible = True
        End
    Sub
     

    Output:-

    DateTimePicker7.gif

    DateTimePicker2.gif

    DateTimePicker3.gifDateTimePicker3.1.gif

    DateTimePicker6.gifDateTimePicker5.gif

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor