本压缩包包括了VC++基础例子编程,可以为您提供方便.
源代码在线查看: form1.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+"日"; }
}
}