MainForm.cs 3.6 KB

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