⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinApp6_6日期时间类
{
    public partial class Form1 : Form
    {
        Date date;   // 声明日期类对象
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            date = new Date();
            date.Year = Convert.ToUInt32( DateTime.Now.Year);
            date.Month = Convert.ToUInt32(DateTime.Now.Month);
            date.Day = Convert.ToUInt32(DateTime.Now.Day);
            lblInfo.Text = "对象创建成功!\n对象当前值为:\n"
                + date.ShowYMD();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            lblInfo.Text = "对象原值为:\n" + date.ShowYMD() + "\n";
            date.AddYear();
            lblInfo.Text += "对象当前值为:\n" + date.ShowYMD();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            lblInfo.Text = "对象原值为:\n" + date.ShowYMD() + "\n";
            date.AddMonth();
            lblInfo.Text += "对象当前值为:\n" + date.ShowYMD();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            lblInfo.Text = "对象原值为:\n" + date.ShowYMD() + "\n";
            date.AddDay();
            lblInfo.Text += "对象当前值为:\n" + date.ShowYMD();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            lblInfo.Text="对象当前的年份值为:\n" + date.ShowYear();
        }

        private void button6_Click(object sender, EventArgs e)
        {        
            lblInfo.Text = "对象当前的月份值为:\n" + date.ShowMonth();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            lblInfo.Text = "对象当前的日值为:\n" + date.ShowDay();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            lblInfo.Text = "对象当前的年月日值为:\n" + date.ShowYMD();
        }
    }   // 此处为折叠起来的Form1类定义的结尾
    public class Date
    {
        private uint year, month, day;
        public uint Year { get { return year; } set { year = value; } }
        public uint Month { get { return month; } set { month = value; } }
        public uint Day { get { return day; } set { day = value; } }
        public void AddYear() { year++; }
        public void AddMonth() { month++; }
        public void AddDay() { day++; }
        public string ShowYear() { return year.ToString(); }
        public string ShowMonth() { return month.ToString(); }
        public string ShowDay() { return day.ToString(); }
        public string ShowYMD()
        { return year.ToString() +"年"+ month+"月" + day+"日"; }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -