123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- using DayOf1440.UI;
- using DayOf1440.Utils;
- 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 : BaseForm
- {
- Bitmap[] charNum=new Bitmap[10];
-
- public MainForm()
- {
- InitializeComponent();
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- loadChar();
- setPanelToCenter();
- // 让屏幕常亮
- SystemSleep.PreventForCurrentThread();
- initCircleStyle();
- timer1.Start();
- }
- private void MainForm_DoubleClick(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- updateTime();
- circleStyle();
- }
- //
- private int[] getScreenSize(){
- // 获取屏幕大小
- int width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
- int height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
- int[] res = { width, height };
- return res;
- }
- private void initCircleStyle(){
- int[] size = getScreenSize();
- label1.Width = size[0];
- label2.Height = size[1];
- label3.Width = size[0];
- label4.Height= size[1];
- }
- /// 边框倒计时效果
- private void circleStyle(){
- int[] size = getScreenSize();
- int second = DateTime.Now.Second;
- if(second==0){
- label1.Location = new Point(0,0);
- label2.Location = new Point(size[0]-23,0);
- label3.Location = new Point(0,size[1]-23);
- label4.Location = new Point(0,0);
- }else if(second<10){
- label1.Location = new Point(0,0);
- label2.Location = new Point(size[0]-23,0);
- label3.Location = new Point(0,size[1]-23);
- label4.Location = new Point(0, size[1]/10*second);
- }else if(second<30){
- label1.Location = new Point(0,0);
- label2.Location = new Point(size[0]-23,0);
- label3.Location = new Point(size[0]/20*(second-10),label3.Location.Y);
- label4.Location = new Point(0, size[1]/10*second);
- }else if (second<40)
- {
- label1.Location = new Point(0,0);
- label2.Location = new Point(label2.Location.X, -size[1]/10*(second-30));
- label3.Location = new Point(size[0]/20*(second-10),label3.Location.Y);
- label4.Location = new Point(0, size[1]/10*second);
- }else
- {
- label1.Location = new Point(-size[0]/20*(second-40),label1.Location.Y);
- label2.Location = new Point(label2.Location.X, -size[1]/10*(second-30));
- label3.Location = new Point(size[0]/20*(second-10),label3.Location.Y);
- label4.Location = new Point(0, size[1]/10*second);
- }
- }
- 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);
- }
- private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- // 取消常亮
- SystemSleep.RestoreForCurrentThread();
- }
- private void cms_life_Click(object sender, EventArgs e)
- {
- //跳转到 人生进度条 界面
- Go(typeof(LifeForm));
- }
- }
- }
|