Wednesday, 22 May 2013

C# How To Pick date and time and save to form application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DatePicker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            DateTime dropOffDate = dateTimePicker1.Value;

            if (dropOffDate.DayOfWeek == DayOfWeek.Friday || dropOffDate.DayOfWeek == DayOfWeek.Saturday || dropOffDate.DayOfWeek == DayOfWeek.Sunday)

                outputLabel.Text = dropOffDate.AddDays(3).ToLongDateString();

            else
                outputLabel.Text = dropOffDate.AddDays(2).ToLongDateString();


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dateTimePicker1.MinDate = DateTime.Today;

            dateTimePicker1.MaxDate = DateTime.Today.AddYears(1);
        }


    }
}


No comments:

Post a Comment