C#自定义一个时间类
2016-12-20 18:17
676 查看
自定义一个时间类,该类包括时、分、秒字段与属性,具有将时间增加1秒、1分和1小时的方法,具有分别显示时、分、秒和同时显示时分秒的方法。
namespace WindowsFormsApplication10 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { time t = new time(); t.second = int.Parse(textBox3.Text); t.minute = int.Parse(textBox2.Text); t.hour = int.Parse(textBox1.Text); if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") return; if (t.second == 59) { textBox3.Text = "00"; t.minute++; if(t.minute==60) { textBox2.Text = "00"; if (t.hour == 23) textBox1.Text = "0"; if(t.hour < 23&&t.hour>=0) textBox1.Text= t.Hour(t.hour).ToString(); if (t.hour > 24 || t.hour < 0) label1.Text = "→_→"; } if (t.minute < 59 && t.minute >= 0) textBox2.Text = t.minute.ToString(); if (t.minute > 60 || t.minute < 0) label1.Text = "→_→"; } if (t.second < 59 && t.second >= 0) { textBox3.Text = t.Second(t.second).ToString(); } if (t.second > 60 || t.second < 0) label1.Text = "→_→"; } private void button2_Click(object sender, EventArgs e) { time t = new time(); t.hour = int.Parse(textBox1.Text); t.minute = int.Parse(textBox2.Text); if (textBox1.Text == "" || textBox2.Text == "") return; if (t.minute == 59) { textBox2.Text = "00"; t.hour++; if (t.hour == 24) textBox1.Text = "00"; if (t.hour < 23 && t.hour >= 0) textBox1.Text = t.hour.ToString(); if (t.hour > 24 || t.hour < 0) label1.Text = "→_→"; } if (t.minute < 59&&t.minute>=0) { textBox2.Text = t.Minute(t.minute).ToString(); } if (t.minute > 60 || t.minute < 0) label1.Text = "→_→"; } private void button1_Click(object sender, EventArgs e) { time t = new time(); t.hour = int.Parse(textBox1.Text); if (textBox1.Text == "") return; if (t.hour == 23) textBox1.Text = "00"; if (t.hour < 23 && t.hour >= 0) { textBox1.Text = t.Hour(t.hour).ToString(); } else label1.Text = "→_→"; } private void button4_Click(object sender, EventArgs e) { label1.Text= textBox1.Text + "小时"; } private void button5_Click(object sender, EventArgs e) { label1.Text = textBox2.Text + "分"; } private void button6_Click(object sender, EventArgs e) { label1.Text = textBox3.Text + "秒"; } private void button7_Click(object sender, EventArgs e) { label1.Text = textBox1.Text + "时" + textBox2.Text + "分" + textBox3.Text + "秒"; } } class time { public int hour, minute, second;//声明字段 public int hourr//声明属性 { get { return hour; } set { hour = value; } } public int minutee { get { return minute; } set { minute = value; } } public int secondd { get { return second; } set { second = value; } } public int Hour(int hour)//声明方法 { hour++; return hour; } public int Minute(int minute) { minute++; return minute; } public int Second(int second) { second++; return second; } } }
相关文章推荐
- 一个自定义LABEL组件的C#源代码
- 本人有时间做了一个日程安排和名片管理系统,B/S结构,sql+ASP.NET(C#),赠送大家免费使用,需要的请留下EMAIL!
- 一个简单方法完成C#时间间隔的计算
- 一个简单方法完成C#时间间隔的计算
- 一个简单方法完成C#时间间隔的计算
- 一个自定义窗口属性的控件(C#)
- 一个简单方法完成C#时间间隔的计算
- 用C#怎样读取一个视频文件的播放时间
- 如何构造一个C#语言的爬虫程序开发者在线 Builder.com.cn 更新时间:2008-07-20作者: 来源:
- 一个简单方法完成C#时间间隔的计算
- 一个计算周次和本周时间范围的代码(c#)[转]
- C#下面,怎么把一个自定义的结构体写入到文件中去?
- C# 学习自定义控件 再做一个ip地址控件(经过测试的)
- [C#]怎样自定义一个服务器端的控件
- 用C#两周时间写了一个地图编辑器,兼论C#游戏开发杂谈
- 从COM中发送一个自定义消息给C#程序
- 在SqlServer2005 中自定义一个 Split函数与C#中的Split功能一样
- c# 一个中国农历时间的类
- C#在做AE自定义工具时的一个错误——自定义放大工具
- 一个简单方法完成C#时间间隔的计算