[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();
}
}
}