Set Date or Time on Window Form
Now we are going to learn about the datetimepiker in C#.
Introduction
In c# we will use datetimepiker to set the date and time. Now coding for date and time shown below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DateTime result = DateTime.Today.Subtract(TimeSpan.FromDays(0));
dateTimePicker1.Value = result;
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
DateTime result = dateTimePicker1.Value;
this.Text = result .ToString ();
}
}
}
Output