MainForm.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. initCircleStyle();
  28. timer1.Start();
  29. }
  30. private void MainForm_DoubleClick(object sender, EventArgs e)
  31. {
  32. Application.Exit();
  33. }
  34. private void timer1_Tick(object sender, EventArgs e)
  35. {
  36. updateTime();
  37. circleStyle();
  38. }
  39. //
  40. private int[] getScreenSize(){
  41. // 获取屏幕大小
  42. int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
  43. int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
  44. int[] res = { width, height };
  45. return res;
  46. }
  47. private void initCircleStyle(){
  48. int[] size = getScreenSize();
  49. label1.Width = size[0];
  50. label2.Height = size[1];
  51. label3.Width = size[0];
  52. label4.Height= size[1];
  53. }
  54. /// 边框倒计时效果
  55. private void circleStyle(){
  56. int[] size = getScreenSize();
  57. int second = DateTime.Now.Second;
  58. if(second==0){
  59. label1.Location = new Point(0,0);
  60. label2.Location = new Point(size[0]-23,0);
  61. label3.Location = new Point(0,size[1]-23);
  62. label4.Location = new Point(0,0);
  63. }else if(second<10){
  64. label1.Location = new Point(0,0);
  65. label2.Location = new Point(size[0]-23,0);
  66. label3.Location = new Point(0,size[1]-23);
  67. label4.Location = new Point(0, size[1]/10*second);
  68. }else if(second<30){
  69. label1.Location = new Point(0,0);
  70. label2.Location = new Point(size[0]-23,0);
  71. label3.Location = new Point(size[0]/20*(second-10),label3.Location.Y);
  72. label4.Location = new Point(0, size[1]/10*second);
  73. }else if (second<40)
  74. {
  75. label1.Location = new Point(0,0);
  76. label2.Location = new Point(label2.Location.X, -size[1]/10*(second-30));
  77. label3.Location = new Point(size[0]/20*(second-10),label3.Location.Y);
  78. label4.Location = new Point(0, size[1]/10*second);
  79. }else
  80. {
  81. label1.Location = new Point(-size[0]/20*(second-40),label1.Location.Y);
  82. label2.Location = new Point(label2.Location.X, -size[1]/10*(second-30));
  83. label3.Location = new Point(size[0]/20*(second-10),label3.Location.Y);
  84. label4.Location = new Point(0, size[1]/10*second);
  85. }
  86. }
  87. private void updateTime()
  88. {
  89. // DateTime.Now 计算当天过去多少分钟
  90. DateTime now = DateTime.Now;
  91. int result= (int)(1440 - DateTime.Now.Subtract(DateTime.Today).TotalMinutes);
  92. int ge=result % 10;
  93. int shi = result / 10 % 10;
  94. int bai = result / 100 % 10;
  95. int qian = result / 1000 % 10;
  96. // 居中显示时间,加特效
  97. if (result >= 1000)
  98. {
  99. pictureBox1.BackgroundImage = charNum[qian];
  100. pictureBox2.BackgroundImage = charNum[bai];
  101. pictureBox3.BackgroundImage = charNum[shi];
  102. pictureBox4.BackgroundImage = charNum[ge];
  103. }
  104. else if (result >= 100)
  105. {
  106. pictureBox1.BackgroundImage = null;
  107. pictureBox2.BackgroundImage = charNum[bai];
  108. pictureBox3.BackgroundImage = charNum[shi];
  109. pictureBox4.BackgroundImage = charNum[ge];
  110. }
  111. else if (result >= 10)
  112. {
  113. pictureBox1.BackgroundImage = null;
  114. pictureBox2.BackgroundImage = charNum[shi];
  115. pictureBox3.BackgroundImage = charNum[ge];
  116. pictureBox4.BackgroundImage = null;
  117. } else
  118. {
  119. pictureBox1.BackgroundImage = null;
  120. pictureBox2.BackgroundImage = charNum[ge];
  121. pictureBox3.BackgroundImage = null;
  122. pictureBox4.BackgroundImage = null;
  123. }
  124. }
  125. private void loadChar()
  126. {
  127. charNum[0] = Properties.Resources._0;
  128. charNum[1] = Properties.Resources._1;
  129. charNum[2] = Properties.Resources._2;
  130. charNum[3] = Properties.Resources._3;
  131. charNum[4] = Properties.Resources._4;
  132. charNum[5] = Properties.Resources._5;
  133. charNum[6] = Properties.Resources._6;
  134. charNum[7] = Properties.Resources._7;
  135. charNum[8] = Properties.Resources._8;
  136. charNum[9] = Properties.Resources._9;
  137. }
  138. /// <summary>
  139. /// 居中
  140. /// </summary>
  141. private void setPanelToCenter() {
  142. panelNum.Location = new Point((System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width-596)/2,(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height-202)/2);
  143. }
  144. private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
  145. {
  146. // 取消常亮
  147. SystemSleep.RestoreForCurrentThread();
  148. }
  149. private void cms_life_Click(object sender, EventArgs e)
  150. {
  151. //跳转到 人生进度条 界面
  152. Go(typeof(LifeForm));
  153. }
  154. }
  155. }