本帖最后由 XhyEax 于 2015-6-5 12:12 编辑
///高三的学长,高考加油!
更新:年级选择(好吧,就是一个ComboBox,默认高三,也可以在txt里面改)
你可以直接在程序中修改年级,也可以修改txt。(只可以输入以下年级:初一、初二、初三、高一、高二、高三)
前言:超级简单的一个C#程序,时间相减就可以得到结果,再加了一个Timer。
给有需要的人。
没加图标,无壳,可以自己添加图标。
截图:
源码(代码有点长,建议大家下载来看):
[C#] 纯文本查看 复制代码 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ExamDayCount
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (File.Exists(Application.StartupPath + "/Grade.txt"))
{
StreamReader sr = new StreamReader(Application.StartupPath + "/Grade.txt", false);
string grade = sr.ReadLine();
sr.Close();
Grade(grade);
}
else
{
MessageBox.Show("年级文件被删除!将在程序启动路径下生成Grade.txt文件并写入【高三】!");
string grade = "高三";
string file = Application.StartupPath + "/Grade.txt";
FileStream myFs = new FileStream(file, FileMode.Create);
StreamWriter mySw = new StreamWriter(myFs);
mySw.Write(grade);
comboBox1.Text = grade;
mySw.Close();
myFs.Close();
}
}
private void Grade(string grade)
{
comboBox1.Text = grade;
switch(grade)
{
case "初一": dateTimeExam.Value = Convert.ToDateTime("2020-6-7"); labOnly.Text = "距2020高考还有:"; comboBox1.Text = "初一";
break;
case "初二": dateTimeExam.Value = Convert.ToDateTime("2019-6-7"); labOnly.Text = "距2019高考还有:"; comboBox1.Text = "初二";
break;
case "初三": dateTimeExam.Value = Convert.ToDateTime("2018-6-7"); labOnly.Text = "距2018高考还有:"; comboBox1.Text = "初三";
break;
case "高一": dateTimeExam.Value = Convert.ToDateTime("2017-6-7"); labOnly.Text = "距2017高考还有:"; comboBox1.Text = "高一";
break;
case "高二": dateTimeExam.Value = Convert.ToDateTime("2016-6-7"); labOnly.Text = "距2016高考还有:"; comboBox1.Text = "高二";
break;
case "高三": dateTimeExam.Value = Convert.ToDateTime("2015-6-7"); labOnly.Text = "距2015高考仅有:"; comboBox1.Text = "高三";
break;
default: dateTimeExam.Value = Convert.ToDateTime("2016-6-7");
break;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
dateTimeNow.Value = DateTime.Now;
DateTime t1 = dateTimeExam.Value;
DateTime t2 = Convert.ToDateTime(DateTime.Now);
TimeSpan ts = t1 - t2;
labDays.Text = Convert.ToString(ts.Days) + "天";
labHours.Text = Convert.ToString(ts.Hours) + "时";
labMin.Text = Convert.ToString(ts.Minutes) + "分";
labS.Text = Convert.ToString(ts.Seconds) + "秒";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Grade(comboBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
string grade = comboBox1.Text;
string file = Application.StartupPath + "/Grade.txt";
FileStream myFs = new FileStream(file, FileMode.Create);
StreamWriter mySw = new StreamWriter(myFs);
mySw.Write(grade+"\n注意:第一行只可以输入以下年级:\n\n初一\n初二\n初三\n高一\n高二\n高三");
comboBox1.Text = grade;
mySw.Close();
myFs.Close();
MessageBox.Show("已写入年级【"+grade+"】!");
}
}
}
下载链接:
土豪通道:
ExamDayCount(成品 源码)【年级选择】.zip
(63.84 KB, 下载次数: 12)
(成品在DayCount\bin\Debug中。)
百度网盘链接:
http://pan.baidu.com/s/1jGteJdW
最后,求评分
|