MainForm.cs 3.1 KB

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