ASP.NET DateTimePicker in VB.NET

In this article you will learn what is DateTimePicker control,its property and how to use it.
  • 6962
 

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:-

    SelectDate-In-DateTimePicker.gif

    GetTime-DateTimePicker.gif

    Hide-DateTimePicker.gifConfirm-to-hide-data_time_picker.gif

    Show-DateTimePicker.gif Confirm-to-show-DateTimePicker.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.