Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
How to use Date Time Picker Control in VB and C# (.net 2.0).

Author: Zunnair
Download Source Code : 887_window control.zip

In this simple article you will learn that how we can use date time picker control in our application using VB and C# .net 2.0.

 

What is Date Time Picker?
Date time picker control is provided by dot net which provides help to select the time and date at run time. This is very help full control.
Value:
To get what value is selected by the user we have a property named value. This property returns an object of date time class which has the values. The current values which are selected in date time picker control is returned by value property.
To demonstrate this make a window application drag date time picker control, one button and one text box on form. Press the button and you will get values in text box.
Now write the following code on button click event:
 C#
private void btn_getvalue_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            string str;
            obj = dateTimePicker1.Value;
            str = obj.ToString();
            textBox1.Text=str;
        }
VB
Private Sub btn_getvalue_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        Dim str As String
        obj = dateTimePicker1.Value
        str = obj.ToString()
        textBox1.Text = str
    End Sub
This simple code gets the value which is selected in date time picker control.
Hide Control:
You can also hide the control. For this purpose dot net provides us a function named hide. This function takes no parameter and returns nothing. It just hides the control for user.
To demonstrate this make a window application drag date time picker control and one button. Press the button.
Now write the following code on button click event:
 C#
private void btn_hide_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Hide();
            MessageBox.Show("control hide");
        }
 VB
Private Sub btn_hide_Click(ByVal sender As Object, ByVal e As EventArgs)
        dateTimePicker1.Hide()
        MessageBox.Show("control hide")
    End Sub
This simple code hides the control.
Show Control:
If the control is hidden and you want to show it again for this purpose dot net provides a function named show.
To demonstrate this make a window application drag date time picker control and one button. Press the button.
Now write the following code on button click event:
C#
private void btn_show_Click(object sender, EventArgs e)
        {
            dateTimePicker1.Show();
            MessageBox.Show("control show");
        }
VB
Private Sub btn_show_Click(ByVal sender As Object, ByVal e As EventArgs)
        dateTimePicker1.Show()
        MessageBox.Show("control show")
    End Sub
This simple code shows the control.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "DEVASP Date Time Picker APPLICATION";
            notifyIcon1.Visible = true;
        }     
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Me.Text = "DEVASP Date Time Picker APPLICATION"
        notifyIcon1.Visible = True
    End Sub
 
This simple article tells that how we can use date time picker control in our application using VB and C# .net 2.0.

 

Article Comments
THANK you for this
i want to compare the current date and entered date to calculate future or previous dates............ as soon as possible soluve this problem send it to my id..............

Posted on 5/5/2010 3:53:07 AM by Akshay

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to use Notify Icon Control in VB and C# (.net 2.0).

Disclaimer - Privacy
© 2002-2014 DevASP.net