吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6114|回复: 18
收起左侧

[其他转载] 桌面版罗马时钟

[复制链接]
苏提春晓 发表于 2021-5-7 18:16
女朋友刷B站看到了一个web实现罗马时钟视频,她觉得很好看,想要一个桌面版的,就随手做了个。功能比较简单,就直接放代码了。效果如图。程序全屏运行,设置了背景透明和鼠标穿透。所以基本相当于桌面存在(但是会浮在桌面图标上方,后面有时间看能不能处理成壁纸那样)。隐藏了任务栏图标,所以退出要从任务管理器杀死(后面优化),附件是我编译好的程序。 xiaozhou.zip (6.99 KB, 下载次数: 144)

QQ图片20210507181134.png
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace xiaozhou
{
    public partial class Form1 : Form
    {
        int fontSize = 16;
        string[] month = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
        string[] days = { "1号", "2号", "3号", "4号", "5号", "6号", "7号", "8号", "9号", "10号", "11号", "12号", "13号", "14号", "15号", "16号", "17号", "18号", "19号", "20号", "21号", "22号", "23号", "24号", "25号", "26号", "27号", "28号", "29号", "30号" , "31号" };
        string[] hours = { "0点", "1点", "2点", "3点", "4点", "5点", "6点", "7点", "8点", "9点", "10点", "11点", "12点", "13点", "14点", "15点", "16点", "17点", "18点", "19点", "20点", "21点", "22点", "23点" };
        string[] mins = { "1分", "2分", "3分", "4分", "5分", "6分", "7分", "8分", "9分", "10分", "11分", "12分", "13分", "14分", "15分", "16分", "17分", "18分", "19分", "20分", "21分", "22分", "23分", "24分", "25分", "26分", "27分", "28分", "29分", "30分", "31分", "32分", "33分", "34分", "35分", "36分", "37分", "38分", "39分", "40分", "41分", "42分", "43分", "44分", "45分", "46分", "47分", "48分", "49分", "50分", "51分", "52分", "53分", "54分", "55分", "56分", "57分", "58分", "59分", "60分" };
        string[] secs = { "1秒", "2秒", "3秒", "4秒", "5秒", "6秒", "7秒", "8秒", "9秒", "10秒", "11秒", "12秒", "13秒", "14秒", "15秒", "16秒", "17秒", "18秒", "19秒", "20秒", "21秒", "22秒", "23秒", "24秒", "25秒", "26秒", "27秒", "28秒", "29秒", "30秒", "31秒", "32秒", "33秒", "34秒", "35秒", "36秒", "37秒", "38秒", "39秒", "40秒", "41秒", "42秒", "43秒", "44秒", "45秒", "46秒", "47秒", "48秒", "49秒", "50秒", "51秒", "52秒", "53秒", "54秒", "55秒", "56秒", "57秒", "58秒", "59秒", "60秒" };
        public Form1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
        }
        /// <summary>
        /// 获取时间戳
        /// </summary>
        /// <returns></returns>
        public string GetTimeStamp()
        {
            TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt64(ts.TotalSeconds).ToString();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Console.WriteLine(DateTime.Now.Year);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.BackColor = Color.Black;
            this.TransparencyKey = this.BackColor;
            SetWindowLong(this.Handle, -20, 0x20 | 0x80000);
            Timer timer2 = new Timer();
            timer2.Interval = 1000;//设置中断时间 单位ms
            timer2.Enabled = true;
            timer2.Tick += new EventHandler(timer1EventProcessor);//添加事件
        }
        private void timer1EventProcessor(object sender, EventArgs e)
        {
            Form1_Paint(sender, null);
        }
        [DllImport("user32.dll")]
        public static extern uint SetWindowLong(IntPtr h, int n, uint x);

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            int interval = 50;//每个圆环的间隔
            int nowMonth = DateTime.Now.Month - 1;
            int nowDay = DateTime.Now.Day - 1;
            int nowHour = DateTime.Now.Hour ;
            int nowMin = DateTime.Now.Minute ;
            int nowSec = DateTime.Now.Second ;
            Graphics g = this.CreateGraphics();
            //单色填充
            SolidBrush b1 = new SolidBrush(Color.Gray);//定义单色画刷
            SolidBrush b2 = new SolidBrush(Color.Red);//定义单色画刷 
            var format = new StringFormat()
            {
                Alignment = StringAlignment.Near,
                LineAlignment = StringAlignment.Near,
            };
            interval = (Height / 2 - 50) / 5;//最大半径5等分
            //转变坐标轴角度
            g.Clear(Color.Black);
            g.TranslateTransform(Width/2, Height/2);
            Console.WriteLine("test");
            for (int i = 0; i < month.Length; i++)
            {
                if (i == 0)
                {
                    g.DrawString(month[(i+ nowMonth)% month.Length], new Font("Arial", fontSize), b2, 50, 0, format);
                }
                else
                {
                    g.DrawString(month[(i + nowMonth) % month.Length], new Font("Arial", fontSize), b1, 50, 0, format);
                }
                g.RotateTransform(360f / month.Length);//每旋转一度就画一条线
            }
            for (int i = 0; i < days.Length; i++)
            {
                if (i == 0)
                {
                    g.DrawString(days[(i + nowDay) % days.Length], new Font("Arial", fontSize), b2, (50 + interval), 0, format);
                }
                else
                {
                    g.DrawString(days[(i + nowDay) % days.Length], new Font("Arial", fontSize), b1, (50 + interval), 0, format);
                }
                g.RotateTransform(360f / days.Length);//每旋转一度就画一条线
            }
            for (int i = 0; i < hours.Length; i++)
            {
                if (i == 0)
                {
                    g.DrawString(hours[(i + nowHour) % hours.Length], new Font("Arial", fontSize), b2, (50 + interval * 2), 0, format);
                }
                else
                {
                    g.DrawString(hours[(i + nowHour) % hours.Length], new Font("Arial", fontSize), b1, (50 + interval * 2), 0, format);
                }
                g.RotateTransform(360f / hours.Length);//每旋转一度就画一条线
            }
            for (int i = 0; i < mins.Length; i++)
            {
                if (i == 0)
                {
                    g.DrawString(mins[(i + nowMin-1) % mins.Length], new Font("Arial", fontSize), b2, (50 + interval * 3), 0, format);
                }
                else
                {
                    g.DrawString(mins[(i + nowMin-1) % mins.Length], new Font("Arial", fontSize), b1, (50 + interval * 3), 0, format);
                }
                g.RotateTransform(360f / mins.Length);//每旋转一度就画一条线
            }
            for (int i = 0; i < secs.Length; i++)
            {
                if (i == 0)
                {
                    g.DrawString(secs[(i + nowSec) % secs.Length], new Font("Arial", fontSize), b2, (50 + interval * 4), 0, format);
                }
                else
                {
                    g.DrawString(secs[(i + nowSec) % secs.Length], new Font("Arial", fontSize), b1, (50 + interval * 4), 0, format);
                }
                g.RotateTransform(360f / secs.Length);//每旋转一度就画一条线
            }
            g.Dispose();
        }


    }
}

免费评分

参与人数 2吾爱币 +6 热心值 +2 收起 理由
Airey + 1 + 1 用心讨论,共获提升!
苏紫方璇 + 5 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 苏提春晓 发表于 2021-6-10 17:30
伪装雨天 发表于 2021-5-25 19:35
有办法让它转的时候不跳嘛,这样一直跳挺晃眼的

这个我没找到好的解决办法,不重绘的话又残影影响。我可以给你一个思路,你可以尝试不用绘图 用label标签 ,但是label怎么旋转我没太细看
 楼主| 苏提春晓 发表于 2021-5-8 13:14
校友网 发表于 2021-5-7 20:45
我有个好看的html页面想做成桌面怎么弄,我看steam里面的哪个软件是可以的,但是不想为了一个壁纸下载个大 ...

这方面我不太清楚,因为我这个简单,所以直接复刻的
Airey 发表于 2021-5-7 20:39
有学习桌面程序应用开发的推荐吗?emmm,这款软件是c#写的吗
caochunji 发表于 2021-5-25 13:09
没附带源码
wulix 发表于 2021-5-25 18:08
感谢分享,我去做一个。
伪装雨天 发表于 2021-5-25 19:35
有办法让它转的时候不跳嘛,这样一直跳挺晃眼的
三滑稽甲苯 发表于 2021-6-10 23:15
@校友网 Wallpaper Engine
伪装雨天 发表于 2021-6-15 15:56
苏提春晓 发表于 2021-6-10 17:30
这个我没找到好的解决办法,不重绘的话又残影影响。我可以给你一个思路,你可以尝试不用绘图 用label标签 ...

感谢,我有时间去试试
zzz0615 发表于 2021-7-28 20:40
怎么设置呀,求教
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-29 02:40

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表