MainForm.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace DayOf1440
  11. {
  12. public partial class MainForm : Form
  13. {
  14. Bitmap[] charNum=new Bitmap[10];
  15. public MainForm()
  16. {
  17. InitializeComponent();
  18. }
  19. private void MainForm_Load(object sender, EventArgs e)
  20. {
  21. loadChar();
  22. setPanelToCenter();
  23. timer1.Start();
  24. }
  25. private void MainForm_DoubleClick(object sender, EventArgs e)
  26. {
  27. Application.Exit();
  28. }
  29. private void timer1_Tick(object sender, EventArgs e)
  30. {
  31. updateTime();
  32. }
  33. private void updateTime()
  34. {
  35. // DateTime.Now 计算当天过去多少分钟
  36. DateTime now = DateTime.Now;
  37. int result= (int)(1440 - DateTime.Now.Subtract(DateTime.Today).TotalMinutes);
  38. int ge=result % 10;
  39. int shi = result / 10 % 10;
  40. int bai = result / 100 % 10;
  41. int qian = result / 1000 % 10;
  42. // 居中显示时间,加特效
  43. if (result > 1000)
  44. {
  45. pictureBox1.BackgroundImage = charNum[qian];
  46. pictureBox2.BackgroundImage = charNum[bai];
  47. pictureBox3.BackgroundImage = charNum[shi];
  48. pictureBox4.BackgroundImage = charNum[ge];
  49. }
  50. else if (result > 100)
  51. {
  52. pictureBox1.BackgroundImage = null;
  53. pictureBox2.BackgroundImage = charNum[bai];
  54. pictureBox3.BackgroundImage = charNum[shi];
  55. pictureBox4.BackgroundImage = charNum[ge];
  56. }
  57. else if (result > 10)
  58. {
  59. pictureBox1.BackgroundImage = null;
  60. pictureBox2.BackgroundImage = charNum[shi];
  61. pictureBox3.BackgroundImage = charNum[ge];
  62. pictureBox4.BackgroundImage = null;
  63. } else
  64. {
  65. pictureBox1.BackgroundImage = null;
  66. pictureBox2.BackgroundImage = charNum[ge];
  67. pictureBox3.BackgroundImage = null;
  68. pictureBox4.BackgroundImage = null;
  69. }
  70. }
  71. private void loadChar()
  72. {
  73. charNum[0] = Properties.Resources._0;
  74. charNum[1] = Properties.Resources._1;
  75. charNum[2] = Properties.Resources._2;
  76. charNum[3] = Properties.Resources._3;
  77. charNum[4] = Properties.Resources._4;
  78. charNum[5] = Properties.Resources._5;
  79. charNum[6] = Properties.Resources._6;
  80. charNum[7] = Properties.Resources._7;
  81. charNum[8] = Properties.Resources._8;
  82. charNum[9] = Properties.Resources._9;
  83. }
  84. /// <summary>
  85. /// 居中
  86. /// </summary>
  87. private void setPanelToCenter() {
  88. panelNum.Location = new Point((System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width-596)/2,(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height-202)/2);
  89. }
  90. }
  91. }