缘由https://bbs.csdn.net/topics/392551630
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;
using System.Collections;
namespace 解答专用窗体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ImageList 图标集 = new ImageList();
private void Form1_Load(object sender, EventArgs e)
{
int 循环 = 0; ArrayList aa = new ArrayList();
while (循环 < 10) 图标集.Images.Add(Image.FromFile(@System.Environment.CurrentDirectory + "\\数字" + 循环++.ToString() + ".png"));
PictureBox xin = new PictureBox();
图标集.ImageSize = new Size(xin.Width * 1, xin.Height * 1);
foreach (char kj in "123456")
{
xin = new PictureBox();
xin.Name = kj.ToString();
xin.Image = 图标集.Images[0];
xin.Parent = this;
xin.Location = new Point(xin.Width * int.Parse(kj.ToString()), 2);
}
this.DoubleClick += new EventHandler(this_DoubleClick);
}
private void this_DoubleClick(object sender, EventArgs e)
{
Control.ControlCollection 图控件 = this.Controls;
//foreach (Control 图 in 图控件) if (图 is PictureBox) ((PictureBox)图).Image = 图标集.Images[int.Parse(图.Name)];
this.BeginInvoke(new Action(() =>
{
while (true)
{
System.Threading.Thread.SpinWait(999); Application.DoEvents();
DateTime shijian = DateTime.Now;
Image[] sutu = {
图标集.Images[shijian.Hour / 10], 图标集.Images[shijian.Hour % 10],
图标集.Images[shijian.Minute / 10], 图标集.Images[shijian.Minute % 10],
图标集.Images[shijian.Second / 10], 图标集.Images[shijian.Second % 10]};
foreach (Control 图 in 图控件) if (图 is PictureBox)
{
PictureBox tu = ((PictureBox)图);
if ("123456".Contains(tu.Name)) tu.Image = sutu[int.Parse(tu.Name) - 1];
}
}
}));
}
}
}
从整图中获取单个数字区域图
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 C井解答专用窗体
{
public partial class C井解答专用窗体 : Form
{
public C井解答专用窗体()
{
InitializeComponent();
}
int 循环 = 0;
int[][] 图0坐标 = new int[][] { new int[] { 180, 200 }, new int[] { 10, 0 }, new int[] { 175, 0 }, new int[] { 175 * 2 - 20, 0 }, new int[] { 175 * 3 - 25, 0 }, new int[] { 175 * 4 - 25, 0 }, new int[] { 0, 230 }, new int[] { 175 + 10, 230 }, new int[] { 175 * 2 + 10, 230 }, new int[] { 175 * 3 + 10, 230 }, new int[] { 175 * 4 - 5, 230 } },
图1坐标 = new int[][] { new int[] { 150, 200 }, new int[] { 10, 5 }, new int[] { 130, 5 }, new int[] { 130 * 2, 5 }, new int[] { 130 * 3 - 10, 5 }, new int[] { 130 * 4 - 10, 5 }, new int[] { 10, 195 }, new int[] { 130, 195 }, new int[] { 130 * 2 - 10, 195 }, new int[] { 130 * 3 - 10, 195 }, new int[] { 130 * 4 - 15, 195 } },
图4坐标 = new int[][] { new int[] { 180, 270 }, new int[] { 185 * 4 + 25, 275 }, new int[] { 10, 5 }, new int[] { 185 + 5, 5 }, new int[] { 185 * 2 + 5, 5 }, new int[] { 185 * 3 + 10, 5 }, new int[] { 185 * 4 + 10, 5 }, new int[] { 25, 275 }, new int[] { 185 + 15, 275 }, new int[] { 185 * 2 + 10, 275 }, new int[] { 185 * 3 + 25, 275 } },
图5坐标 = new int[][] { new int[] { 140, 185 }, new int[] { 150 * 4, 220 }, new int[] { 0, 10 }, new int[] { 140, 10 }, new int[] { 150 * 2, 10 }, new int[] { 150 * 3 - 10, 10 }, new int[] { 150 * 4, 10 }, new int[] { 0, 220 }, new int[] { 150 - 15, 220 }, new int[] { 150 * 2, 220 }, new int[] { 150 * 3 - 5, 220 } },
图2坐标 = new int[][] { new int[] { 170, 170 }, new int[] { 5, 5 }, new int[] { 170 + 5, 5 }, new int[] { 170 * 2 + 5, 5 }, new int[] { 170 * 3 + 10, 5 }, new int[] { 170 * 4 + 10, 5 }, new int[] { 5, 210 }, new int[] { 170 + 5, 210 }, new int[] { 170 * 2 + 5, 210 }, new int[] { 170 * 3 + 5, 210 }, new int[] { 170 * 4 + 5, 210 } },
图3坐标 = new int[][] { new int[] { 220, 240 }, new int[] { 5, 5 }, new int[] { 210, 5 }, new int[] { 210 * 2 - 20, 5 }, new int[] { 210 * 3 - 30, 5 }, new int[] { 210 * 4 - 50, 5 }, new int[] { 0, 270 }, new int[] { 210, 270 }, new int[] { 210 * 2 - 20, 270 }, new int[] { 210 * 3 - 40, 270 }, new int[] { 210 * 4 - 50, 270 } };
private void C井解答专用窗体_Load(object sender, EventArgs e)
{
//System.Collections.ArrayList aarrayList = new System.Collections.ArrayList();
PictureBox xin = new PictureBox();
foreach (char kj in "12345678ABCDEFGH")
{
xin = new PictureBox();
xin.Name = kj.ToString();
xin.Size = new System.Drawing.Size(50, 100);
if ("12345678".Contains(kj))
{
xin.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字3.jpg", 图3坐标[++循环][0], 图3坐标[循环][1], 图3坐标[0][0], 图3坐标[0][1], xin.Width, xin.Height);
xin.Location = new Point(xin.Width * (int.Parse(kj.ToString())) + 5 * int.Parse(kj.ToString()), 5);
}
if ("ABCDEFGH".Contains(kj))
{
xin.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字2.jpg", 图2坐标[++循环 - 8][0], 图2坐标[循环 - 8][1], 图2坐标[0][0], 图2坐标[0][1], xin.Width, xin.Height);
xin.Location = new Point((xin.Width * (循环 - 8)) + 5 * (循环 - 8), xin.Height + 15);
}
xin.Parent = this;
}
this.DoubleClick += new EventHandler(窗体双击);
}
static System.Drawing.Bitmap 选图区域(string 图片路径, int 原图X, int 原图Y, int 原图宽, int 原图高, int 区域宽, int 区域高)
{//参考https://www.cnblogs.com/zhangruifeng/p/5986463.html
System.Drawing.Image 原图 = System.Drawing.Image.FromFile(图片路径);
System.Drawing.Bitmap 图区 = new System.Drawing.Bitmap(区域宽, 区域高);
System.Drawing.Graphics 新图 = System.Drawing.Graphics.FromImage(图区);
System.Drawing.Rectangle 目标位置 = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(区域宽, 区域高));
System.Drawing.Rectangle 原图位置 = new System.Drawing.Rectangle(new System.Drawing.Point(原图X, 原图Y), new System.Drawing.Size(原图宽, 原图高));
新图.DrawImage(原图, 目标位置, 原图位置, System.Drawing.GraphicsUnit.Pixel);
return 图区;
}
private void 窗体双击(object sender, EventArgs e)
{
Control.ControlCollection 图控件 = this.Controls;
this.BeginInvoke(new Action(() =>
{
while (true)
{
Task.Delay(999); Application.DoEvents();
DateTime shijian = DateTime.Now; 循环 = 6;
int[] sutu = { shijian.Hour / 10, shijian.Hour % 10, shijian.Minute / 10, shijian.Minute % 10, shijian.Second / 10, shijian.Second % 10, Array.IndexOf("Sunday Monday Tuesday Wednesday Thursday Friday Saturday ".Split(' '), shijian.DayOfWeek.ToString()), shijian.Year / 1000, shijian.Year / 100 % 10, shijian.Year / 10 % 10, shijian.Year % 10, shijian.Month / 10 % 10, shijian.Month % 10, shijian.Day / 10 % 10, shijian.Day % 10 };
foreach (Control 图 in 图控件) if (图 is PictureBox)
{
PictureBox tu = ((PictureBox)图);
if ("12".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字0.jpg", 图0坐标[sutu[int.Parse(tu.Name) - 1] + 1][0], 图0坐标[sutu[int.Parse(tu.Name) - 1] + 1][1], 图0坐标[0][0], 图0坐标[0][1], tu.Width, tu.Height);
if ("34".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字5.jpg", 图5坐标[sutu[int.Parse(tu.Name) - 1] + 1][0], 图5坐标[sutu[int.Parse(tu.Name) - 1] + 1][1], 图5坐标[0][0], 图5坐标[0][1], tu.Width, tu.Height);
if ("56".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字4.jpg", 图4坐标[sutu[int.Parse(tu.Name) - 1] + 1][0], 图4坐标[sutu[int.Parse(tu.Name) - 1] + 1][1], 图4坐标[0][0], 图4坐标[0][1], tu.Width, tu.Height);
if ("7".Contains(tu.Name)) tu.Image = new Bitmap(tu.Width, tu.Height );
if ("8".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字0.jpg", 图0坐标[sutu[int.Parse(tu.Name) - 2] + 1][0], 图0坐标[sutu[int.Parse(tu.Name) - 2] + 1][1], 图0坐标[0][0], 图0坐标[0][1], tu.Width, tu.Height);
if ("ABCDGH".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字2.jpg", 图2坐标[sutu[++循环] + 1][0], 图2坐标[sutu[循环] + 1][1], 图2坐标[0][0], 图2坐标[0][1], tu.Width, tu.Height);
if ("EF".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\ICO\\数字3.jpg", 图3坐标[sutu[++循环] + 1][0], 图3坐标[sutu[循环] + 1][1], 图3坐标[0][0], 图3坐标[0][1], tu.Width, tu.Height);
}
}
}));
}
}
}
超级丑修改一下显示时间、星期、年月日
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 微佛诞提示日历时间
{
public partial class 微佛诞提示日历时间 : Form
{
private class 佛诞
{
public string 名称 { get; set; }
public int 日期 { get; set; }
public 佛诞(string 称号, int 诞日)
{ 名称 = 称号; 日期 = 诞日; }
}
佛诞[] 佛诞组 = new 佛诞[] { new 佛诞("那摩阿弥陀佛!圣诞", 1117), new 佛诞("那摩地藏王菩萨!圣诞", 729), new 佛诞("那摩地藏王菩萨!圣诞", 730)
, new 佛诞("那摩释迦牟尼佛!圣诞", 48), new 佛诞("那摩释迦牟尼佛!出家", 28), new 佛诞("那摩释迦牟尼佛!成道", 128), new 佛诞("那摩释迦牟尼佛!涅槃", 215)
, new 佛诞("那摩观世音菩萨!圣诞", 219), new 佛诞("那摩观世音菩萨!出家", 919), new 佛诞("那摩观世音菩萨!成道", 619), new 佛诞("那摩大势至菩萨!圣诞", 713)
, new 佛诞("那摩普贤菩萨!圣诞", 221), new 佛诞("那摩文殊师利菩萨!圣诞", 44), new 佛诞("那摩禅宗达摩祖师!圣诞", 105), new 佛诞("那摩慧能禅宗六祖!圣诞", 29), new 佛诞("那摩慧能禅宗六祖!圆寂", 83)
, new 佛诞("那摩华严菩萨!圣诞", 1229), new 佛诞("那摩药师佛!圣诞", 930), new 佛诞("那摩燃灯古佛!圣诞", 822), new 佛诞("那摩定光佛!圣诞", 16), new 佛诞("那摩弥勒菩萨!圣诞;春节", 11)
, new 佛诞("那摩福德土地正神!圣诞", 22), new 佛诞("那摩准提菩萨!圣诞", 316), new 佛诞("那摩药王菩萨!圣诞", 428), new 佛诞("那摩伽蓝菩萨!圣诞", 518)
, new 佛诞("那摩韦驮菩萨!圣诞", 63), new 佛诞("那摩第五殿阎罗天子!圣诞", 18), new 佛诞("那摩帝释天尊!圣诞", 19), new 佛诞("那摩妈祖升仙!重阳节", 729)
, new 佛诞("那摩妈祖!圣诞", 323), new 佛诞("那摩文昌帝君!圣诞", 23), new 佛诞("那摩第四殿五官王!圣诞", 218), new 佛诞("那摩第六殿卞城王!圣诞", 38)
, new 佛诞("那摩中岳大帝;后土娘娘!圣诞", 319), new 佛诞("那摩子孙娘娘!圣诞", 320), new 佛诞("那摩第七殿泰山王!圣诞", 327), new 佛诞("那摩地藏王菩萨!圣诞", 729)
, new 佛诞("佛欢喜日!盂兰盆节", 715), new 佛诞("元宵节!", 115), new 佛诞("端午节", 55), new 佛诞("七夕情人节", 77), new 佛诞("中秋节", 815), new 佛诞("中秋节", 815)
, new 佛诞("腊八节", 128), new 佛诞("小年", 1223), new 佛诞("除夕", 1230), new 佛诞("道教中元节", 715)};
//System.Collections.ArrayList 佛菩萨圣诞 = new System.Collections.ArrayList();
public 微佛诞提示日历时间()
{
InitializeComponent();
}
ToolTip 控件说明 = new ToolTip();
NotifyIcon 托盘 = new NotifyIcon();
System.Timers.Timer 定时 = new System.Timers.Timer(1000);
System.Globalization.ChineseLunisolarCalendar 微软农历 = new System.Globalization.ChineseLunisolarCalendar();
int 循环 = 0, 天 = 0, 月 = 0, 年 = 0; int[] 提醒组 = { };
int[][] 图0坐标 = new int[][] { new int[] { 180, 200 }, new int[] { 10, 0 }, new int[] { 175, 0 }, new int[] { 175 * 2 - 20, 0 }, new int[] { 175 * 3 - 25, 0 }, new int[] { 175 * 4 - 25, 0 }, new int[] { 0, 230 }, new int[] { 175 + 10, 230 }, new int[] { 175 * 2 + 10, 230 }, new int[] { 175 * 3 + 10, 230 }, new int[] { 175 * 4 - 5, 230 } },
图1坐标 = new int[][] { new int[] { 150, 200 }, new int[] { 10, 5 }, new int[] { 130, 5 }, new int[] { 130 * 2, 5 }, new int[] { 130 * 3 - 10, 5 }, new int[] { 130 * 4 - 10, 5 }, new int[] { 10, 195 }, new int[] { 130, 195 }, new int[] { 130 * 2 - 10, 195 }, new int[] { 130 * 3 - 10, 195 }, new int[] { 130 * 4 - 15, 195 } },
图4坐标 = new int[][] { new int[] { 180, 270 }, new int[] { 185 * 4 + 25, 275 }, new int[] { 10, 5 }, new int[] { 185 + 5, 5 }, new int[] { 185 * 2 + 5, 5 }, new int[] { 185 * 3 + 10, 5 }, new int[] { 185 * 4 + 10, 5 }, new int[] { 25, 275 }, new int[] { 185 + 15, 275 }, new int[] { 185 * 2 + 10, 275 }, new int[] { 185 * 3 + 25, 275 } },
图5坐标 = new int[][] { new int[] { 140, 185 }, new int[] { 150 * 4, 220 }, new int[] { 0, 10 }, new int[] { 140, 10 }, new int[] { 150 * 2, 10 }, new int[] { 150 * 3 - 10, 10 }, new int[] { 150 * 4, 10 }, new int[] { 0, 220 }, new int[] { 150 - 15, 220 }, new int[] { 150 * 2, 220 }, new int[] { 150 * 3 - 5, 220 } },
图2坐标 = new int[][] { new int[] { 170, 170 }, new int[] { 5, 5 }, new int[] { 170 + 5, 5 }, new int[] { 170 * 2 + 5, 5 }, new int[] { 170 * 3 + 10, 5 }, new int[] { 170 * 4 + 10, 5 }, new int[] { 5, 210 }, new int[] { 170 + 5, 210 }, new int[] { 170 * 2 + 5, 210 }, new int[] { 170 * 3 + 5, 210 }, new int[] { 170 * 4 + 5, 210 } },
图3坐标 = new int[][] { new int[] { 220, 240 }, new int[] { 5, 5 }, new int[] { 210, 5 }, new int[] { 210 * 2 - 20, 5 }, new int[] { 210 * 3 - 30, 5 }, new int[] { 210 * 4 - 50, 5 }, new int[] { 0, 270 }, new int[] { 210, 270 }, new int[] { 210 * 2 - 20, 270 }, new int[] { 210 * 3 - 40, 270 }, new int[] { 210 * 4 - 50, 270 } };
//ComboBox 下拉框 = new ComboBox();
//ListBox 项列表 = new ListBox();
//TextBox 姓名 = new TextBox(), 电话 = new TextBox();
//Button 添加 = new Button(), 删除 = new Button();
private void 微佛诞提示日历时间_Load(object sender, EventArgs e)
{
//删除.Parent = 添加.Parent = 电话.Parent = 姓名.Parent = 项列表.Parent = this;
//删除.Anchor = 添加.Anchor = 电话.Anchor = 姓名.Anchor = 项列表.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
//项列表.Location = new Point(2, 2);
//电话.Location = new Point(2, 项列表.Bottom + 5);
//姓名.Location = new Point(电话.Right + 5, 项列表.Bottom + 5);
//添加.Location = new Point(2, 电话.Bottom + 5);
//删除.Location = new Point(添加.Right + 5, 电话.Bottom + 5);
//电话.Text = "电话"; 姓名.Text = "姓名"; 项列表.Items.Add("项列表"); 添加.Text = "添加"; 删除.Text = "删除";
//删除.Click += new EventHandler(删除数据);
//添加.Click += new EventHandler(添加数据);
//截取桌面图片();
//下拉框.Parent = this;
//foreach (string kj in "1 2 3 4 5 6 7 8 9 10 11 12".Split(' ')) 下拉框.Items.Add(kj+"月");
//下拉框.SelectedIndex = DateTime.Now.Month - 1;
PictureBox xin = new PictureBox();
foreach (char kj in "12345678ABCDEFGH")
{
xin = new PictureBox();
xin.Name = kj.ToString();
xin.Size = new System.Drawing.Size(50, 100);
if ("12345678".Contains(kj))
{
xin.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字3.jpg", 图3坐标[++循环][0], 图3坐标[循环][1], 图3坐标[0][0], 图3坐标[0][1], xin.Width, xin.Height);
xin.Location = new Point(xin.Width * (int.Parse(kj.ToString()) - 1) + 5 * int.Parse(kj.ToString()), 5);
}
if ("ABCDEFGH".Contains(kj))
{
xin.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字2.jpg", 图2坐标[++循环 - 8][0], 图2坐标[循环 - 8][1], 图2坐标[0][0], 图2坐标[0][1], xin.Width, xin.Height);
xin.Location = new Point((xin.Right * (循环 - 9)) + 5 * (循环 - 8), xin.Bottom + 15);
}
xin.Parent = this;
}
this.AllowDrop = true; //this.Opacity = .9;
this.DoubleClick += new EventHandler(窗体双击);
this.Resize += new EventHandler(窗体大小);
this.FormClosed += new FormClosedEventHandler(关闭后);
this.DragDrop += new DragEventHandler(窗体拖放);
this.DragEnter += new DragEventHandler(拖入窗体);
//MessageBox.Show("空 格 直接使用现有函数处理".Replace(" ", ""));
月历加载(/*初始*/); 开机启动();
定时.AutoReset = true; 定时.Enabled = true;
定时.Elapsed += new System.Timers.ElapsedEventHandler(定时触发);
托盘.Visible = true; 托盘.Click += new EventHandler(点击托盘);
托盘.Icon = this.Icon = new Icon(@System.Environment.CurrentDirectory + "\\佛像\\八卦.ico");
托盘.BalloonTipTitle = 托盘.Text = "微佛诞图片提示日月历时间,从这里开始!";
Microsoft.Win32.SystemEvents.SessionSwitch += new Microsoft.Win32.SessionSwitchEventHandler(用户登录);
//Microsoft.Win32.SystemEvents.SessionSwitch -= new Microsoft.Win32.SessionSwitchEventHandler(用户登录);
//var 用户 = System.Security.Principal.WindowsIdentity.GetCurrent(false);
//var dsa = 用户;//参考https://bbs.csdn.net/topics/391906081
}
//private void 删除数据(object sender, EventArgs e)
//{
// //if (项列表.GetSelected(项列表.SelectedIndex)) 项列表.Items.RemoveAt(项列表.SelectedIndex);
// foreach (object aa in 项列表.Items)
// if (aa.ToString().Contains(电话.Text)) { 项列表.Items.Remove(aa); break; }
// var dd = 项列表.Items.IndexOf(电话.Text + ":" + 姓名.Text);
// if (dd>=0)
// {
// 项列表.Items.Remove(项列表.Items[dd]);
// //MessageBox.Show("记录删除成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
// }
// else
// MessageBox.Show("用户不存在!", "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
//private void 添加数据(object sender, EventArgs e)
//{
// if (项列表.Items.IndexOf(电话.Text + ":" + 姓名.Text) < 0)
// 项列表.Items.Add(电话.Text + ":" + 姓名.Text);
// else
// MessageBox.Show("用户名已存在!", "出错", MessageBoxButtons.OK, MessageBoxIcon.Error);
//}
private void 关闭后(object sender, FormClosedEventArgs e)
{
托盘.Visible = false;
}
private void 点击托盘(object sender, EventArgs e)
{
this.ShowInTaskbar = !this.ShowInTaskbar;
this.WindowState = this.ShowInTaskbar ? FormWindowState.Normal : FormWindowState.Minimized;
}
private void 用户登录(object sender, Microsoft.Win32.SessionSwitchEventArgs e)
{
switch (e.Reason)
{
case Microsoft.Win32.SessionSwitchReason.SessionLogon:
case Microsoft.Win32.SessionSwitchReason.SessionUnlock:
月历加载(/*屏保*/);
break;
case Microsoft.Win32.SessionSwitchReason.SessionLock:
case Microsoft.Win32.SessionSwitchReason.SessionLogoff:
this.WindowState = FormWindowState.Minimized;
break;
}
}
private void 窗体双击(object sender, EventArgs e)
{
//if (this.Tag != null)
// using (System.IO.FileStream 流 = new System.IO.FileStream(@System.Environment.CurrentDirectory + "\\屏幕\\屏幕" + DateTime.Now.ToShortDateString().Replace("/", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + ".ICO", System.IO.FileMode.Create, System.IO.FileAccess.Write))
// { 无损转换Image为Icon((Bitmap)this.Tag).Save(流); MessageBox.Show(流.Name,"友情提示,图标已经成功生成并保存如下:"); }//C# Image转Icon
}
private void 窗体大小(object sender, EventArgs e)
{/*0还原1最小2最大*/
if (Convert.ToUInt16(this.WindowState) == 0) { this.BackgroundImage = null; 月历加载(/*还原*/); }
if (Convert.ToUInt16(this.WindowState) == 1) this.ShowInTaskbar = false;
if (Convert.ToUInt16(this.WindowState) == 2 && this.Tag != null) 图片适应((Image)this.Tag);
}
private void 拖入窗体(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
//this.BackgroundImage = new Bitmap(new Bitmap(((string[])e.Data.GetData(DataFormats.FileDrop, true))[0]), this.Width, this.Height);
}
private void 窗体拖放(object sender, DragEventArgs e)
{
图片适应(new Bitmap(((string[])e.Data.GetData(DataFormats.FileDrop, true))[0]));
}
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
extern static bool DestroyIcon(IntPtr 处理);//参考https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.icon.fromhandle?redirectedfrom=MSDN&view=netframework-4.7.2#System_Drawing_Icon_FromHandle_System_IntPtr_
private void 定时触发(object sender, System.Timers.ElapsedEventArgs e)
{
//if (Clipboard.ContainsImage())
// this.BackgroundImage = Clipboard.GetImage();
显示图片();
try
{
this.BeginInvoke(new Action(() =>
{
using (Bitmap 旋 = this.Icon.ToBitmap())
{
旋.RotateFlip(RotateFlipType.Rotate90FlipNone);
using (Icon 转 = Icon.FromHandle(旋.GetHicon(/*发生一般性GDI错误*/)))
{ 托盘.Icon = this.Icon = (Icon)转.Clone(); DestroyIcon(转.Handle); }
}
}));
}
catch (Exception)
{ }
}
bool 判断文件存在(string 路径文件名) { return new System.IO.FileInfo(路径文件名).Exists; }
void 月历加载()
{
天 = 微软农历.GetDayOfMonth(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
月 = 微软农历.GetMonth(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day));
年 = 微软农历.GetSexagenaryYear(DateTime.Now); 提醒组 = new int[] { };
foreach (char 查 in "123456") 提醒组 = 提醒组.Concat(new int[] { int.Parse(微软农历.GetMonth(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(int.Parse(查.ToString()))).ToString() + 微软农历.GetDayOfMonth(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(int.Parse(查.ToString()))).ToString()) }).ToArray();
this.Text = "月历:" + " 甲乙丙丁戊己庚辛壬癸"[微软农历.GetCelestialStem(年)]
+ " 鼠牛虎兔龙蛇马羊猴鸡狗猪"[微软农历.GetTerrestrialBranch(年)] + "年"
+ " 正二三四五六七八九十冬腊"[月] + (天 > 10 ? "月" : "月初") + " 十廿仨"[天 / 10] + " 一二三四五六七八九"[天 % 10];
}
void 显示图片()
{
Control.ControlCollection 控件集 = this.Controls;
this.BeginInvoke(new Action(() =>
{
DateTime shijian = DateTime.Now; 循环 = 6; string ts = "";
if (shijian.Hour + shijian.Minute + shijian.Second == 0) 月历加载(/*0点*/);
int[] sutu = { shijian.Hour / 10, shijian.Hour % 10, shijian.Minute / 10, shijian.Minute % 10, shijian.Second / 10, shijian.Second % 10, Array.IndexOf("Sunday Monday Tuesday Wednesday Thursday Friday Saturday ".Split(' '), shijian.DayOfWeek.ToString()), shijian.Year / 1000, shijian.Year / 100 % 10, shijian.Year / 10 % 10, shijian.Year % 10, shijian.Month / 10 % 10, shijian.Month % 10, shijian.Day / 10 % 10, shijian.Day % 10 };
foreach (Control 图 in 控件集) if (图 is PictureBox)
{
PictureBox tu = ((PictureBox)图);
if ("12".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字0.jpg", 图0坐标[sutu[int.Parse(tu.Name) - 1] + 1][0], 图0坐标[sutu[int.Parse(tu.Name) - 1] + 1][1], 图0坐标[0][0], 图0坐标[0][1], tu.Width, tu.Height);
if ("34".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字5.jpg", 图5坐标[sutu[int.Parse(tu.Name) - 1] + 1][0], 图5坐标[sutu[int.Parse(tu.Name) - 1] + 1][1], 图5坐标[0][0], 图5坐标[0][1], tu.Width, tu.Height);
if ("56".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字4.jpg", 图4坐标[sutu[int.Parse(tu.Name) - 1] + 1][0], 图4坐标[sutu[int.Parse(tu.Name) - 1] + 1][1], 图4坐标[0][0], 图4坐标[0][1], tu.Width, tu.Height);
if ("7".Contains(tu.Name))
{
佛诞[] 圣号 = 佛诞组.Where(查 => 查.日期 == int.Parse(月.ToString() + 天.ToString()) || 提醒组.Contains(查.日期)).OrderBy(排 => 提醒组.ToList().IndexOf(排.日期)).ToArray();
tu.Image = new Bitmap(new Bitmap((((圣号.Length > 0) ? 判断文件存在(@System.Environment.CurrentDirectory + "\\佛像\\" + 圣号[0].名称.Split('!')[0] + ".jpg") : false) ? @System.Environment.CurrentDirectory + "\\佛像\\" + 圣号[0].名称.Split('!')[0] + ".jpg" : @System.Environment.CurrentDirectory + "\\佛像\\那摩韦驮菩萨.jpg")), tu.Width, tu.Height);
if (圣号.Length > 0 && 判断文件存在(@System.Environment.CurrentDirectory + "\\佛像\\" + 圣号[0].名称.Split('!')[0] + ".jpg"))
this.Tag = new Bitmap(@System.Environment.CurrentDirectory + "\\佛像\\" + 圣号[0].名称.Split('!')[0] + ".jpg");// else this.Tag = null;
foreach (var 圣 in 圣号) ts += 圣.名称 + (提醒组.ToList().IndexOf(圣.日期) + 1) + "天;";
if (圣号.Length > 0)
{
int 预 = 提醒组.ToList().IndexOf(圣号[0].日期) + 1;
控件说明.SetToolTip(tu, ts.Replace("0", "今"));
if (shijian.Second % (2 + 预) == 0 && !this.Text.Contains("(提醒!)" + 预.ToString("0天").Replace("0", "今"))) this.Text += "(提醒!)" + 预.ToString("0天").Replace("0", "今"); else this.Text = this.Text.Replace("(提醒!)" + 预.ToString("0天").Replace("0", "今"), "");
}
else if (this.Tag == null) this.Tag = new Bitmap(@System.Environment.CurrentDirectory + "\\佛像\\韦驮菩萨.jpg");
}
if ("8".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字0.jpg", 图0坐标[sutu[int.Parse(tu.Name) - 2] + 1][0], 图0坐标[sutu[int.Parse(tu.Name) - 2] + 1][1], 图0坐标[0][0], 图0坐标[0][1], tu.Width, tu.Height);
if ("ABCDGH".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字2.jpg", 图2坐标[sutu[++循环] + 1][0], 图2坐标[sutu[循环] + 1][1], 图2坐标[0][0], 图2坐标[0][1], tu.Width, tu.Height);
if ("EF".Contains(tu.Name)) tu.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字3.jpg", 图3坐标[sutu[++循环] + 1][0], 图3坐标[sutu[循环] + 1][1], 图3坐标[0][0], 图3坐标[0][1], tu.Width, tu.Height);
}
}));
}
void 开机启动()
{//选择 COM 选项卡并选择 Windows Script Host Object Model
string 程序名 = Application.ExecutablePath,
名称 = 程序名.Substring(程序名.LastIndexOf("\\") + 1);
名称 = 名称.Remove(名称.LastIndexOf("."));
if (!System.IO.File.Exists(程序名)) return;
string 快捷文件 = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + 名称 + ".lnk";
if (System.IO.File.Exists(快捷文件))
{
//if (MessageBox.Show("确定要删除 [" + 名称 + "] 开机启动吗?", "删除确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
// System.IO.File.Delete(快捷文件);
}
else
{
if (MessageBox.Show("确定要创建 [" + 名称 + "] 开机启动吗?", "创建确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
IWshRuntimeLibrary.WshShell 外壳 = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut 快捷键 = (IWshRuntimeLibrary.IWshShortcut)外壳.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + 名称 + ".lnk");
快捷键.TargetPath = 程序名;
快捷键.WorkingDirectory = System.Environment.CurrentDirectory;
快捷键.WindowStyle = 1;
快捷键.Description = 名称;
快捷键.IconLocation = 程序名;
快捷键.Save();
}
MessageBox.Show("[" + 名称 + "] 开机启动,设置完成!");
}
}
void 图片适应(Image 原图)
{
double 比率 = 1; int 标题高 = 28;
if (原图.Height > this.Height) 比率 = (double)(this.Height - 标题高) / (double)原图.Height;
if (原图.Width > this.Width) 比率 = (double)(this.Width) / 原图.Width;
if (原图.Height > this.Height && 原图.Width > this.Width)
比率 = ((double)(this.Height - 标题高) / (double)原图.Height) > ((double)(this.Width) / 原图.Width) ? (double)(this.Width) / 原图.Width : ((double)(this.Height - 标题高) / (double)原图.Height);
this.Tag = this.BackgroundImage = 高质缩略图(原图, (int)(原图.Width * 比率), (int)(原图.Height * 比率), new Bitmap(this.Width, this.Height - 标题高));
}
static System.Drawing.Bitmap 选图区域(string 图片路径, int 原图X, int 原图Y, int 原图宽, int 原图高, int 区域宽, int 区域高)
{//参考https://www.cnblogs.com/zhangruifeng/p/5986463.html
System.Drawing.Bitmap 图区 = new System.Drawing.Bitmap(区域宽, 区域高);
try
{
System.Drawing.Image 原图 = System.Drawing.Image.FromFile(图片路径);
System.Drawing.Graphics 新图 = System.Drawing.Graphics.FromImage(图区);
System.Drawing.Rectangle 目标位置 = new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), new System.Drawing.Size(区域宽, 区域高));
System.Drawing.Rectangle 原图位置 = new System.Drawing.Rectangle(new System.Drawing.Point(原图X, 原图Y), new System.Drawing.Size(原图宽, 原图高));
新图.DrawImage(原图, 目标位置, 原图位置, System.Drawing.GraphicsUnit.Pixel);
//.Save(@System.Environment.CurrentDirectory + "\\屏幕\\屏幕" + DateTime.Now.ToShortDateString().Replace("/", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch { }
finally { }
return 图区;
}
}
}