C#/C#200제

[C#] 20일차 - 149. DateTimePicker를 이용한 날짜 계산기

반나무 2021. 2. 23. 00:27

DateTimePicker 달력

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 A149_DateTimePicker
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

            txtDates.Text = today.Subtract(selectedDay).TotalDays.ToString("0");
        }
    }
}

반응형