1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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 DayOf1440
- {
- public partial class MainForm : Form
- {
- Bitmap[] charNum=new Bitmap[10];
- public MainForm()
- {
- InitializeComponent();
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- loadChar();
- }
- private void MainForm_DoubleClick(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- updateTime();
- setPanelToCenter();
- }
- private void updateTime()
- {
- // DateTime.Now 计算当天过去多少分钟
- DateTime now = DateTime.Now;
- int result= (int)(1440 - DateTime.Now.Subtract(DateTime.Today).TotalMinutes);
- int ge=result % 10;
- int shi = result / 10 % 10;
- int bai = result / 100 % 10;
- int qian = result / 1000 % 10;
- // 居中显示时间,加特效
- if (result > 1000)
- {
- pictureBox1.BackgroundImage = charNum[qian];
- pictureBox2.BackgroundImage = charNum[bai];
- pictureBox3.BackgroundImage = charNum[shi];
- pictureBox4.BackgroundImage = charNum[ge];
- }
- else if (result > 100)
- {
- pictureBox1.BackgroundImage = null;
- pictureBox2.BackgroundImage = charNum[bai];
- pictureBox3.BackgroundImage = charNum[shi];
- pictureBox4.BackgroundImage = charNum[ge];
- }
- else if (result > 10)
- {
- pictureBox1.BackgroundImage = null;
- pictureBox2.BackgroundImage = charNum[shi];
- pictureBox3.BackgroundImage = charNum[ge];
- pictureBox4.BackgroundImage = null;
- } else
- {
- pictureBox1.BackgroundImage = null;
- pictureBox2.BackgroundImage = charNum[ge];
- pictureBox3.BackgroundImage = null;
- pictureBox4.BackgroundImage = null;
- }
- }
- private void loadChar()
- {
- charNum[0] = Properties.Resources._0;
- charNum[1] = Properties.Resources._1;
- charNum[2] = Properties.Resources._2;
- charNum[3] = Properties.Resources._3;
- charNum[4] = Properties.Resources._4;
- charNum[5] = Properties.Resources._5;
- charNum[6] = Properties.Resources._6;
- charNum[7] = Properties.Resources._7;
- charNum[8] = Properties.Resources._8;
- charNum[9] = Properties.Resources._9;
- }
- /// <summary>
- /// 居中
- /// </summary>
- private void setPanelToCenter() {
- panelNum.Location = new Point((System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width-596)/2,(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height-202)/2);
- }
- }
- }
|