Home  >  Article  >  WeChat Applet  >  CnClock desktop clock-Winform applet development

CnClock desktop clock-Winform applet development

高洛峰
高洛峰Original
2017-02-23 14:36:593832browse

I couldn’t access the Internet when I went home during the Chinese New Year. I was bored the past two days and so I researched a small program by myself. Let’s take a look at the interface of the program first:

Interface one:

CnClock桌面时钟-Winform小程序开发

Interface two:

CnClock桌面时钟-Winform小程序开发

##This small program took more than a day to write. The function is relatively simple. The functions of this program are:

1. It can display the date, current time, week, and lunar calendar.

2. The program can be adsorbed on the desktop to achieve the effect of being embedded in the desktop.

3. You can set the program to start automatically at boot.

Part of the main code is posted below:

//设置吸附桌面功能 
 private void 吸附桌面ToolStripMenuItem_CheckStateChanged(object sender, EventArgs e) 
 ...{ 
 //默认为勾选状态(吸附桌面),点击后即触发该事件,“吸附桌面”项勾掉了,则变量ischecked为!ischecked(false), 
 //则可以移动窗体。再次点击该菜单项,ischecked为!ischecked(true),则不能移动窗体。 
 //checkstate发生变化 
 ischecked = !ischecked; 
 if (ischecked == true) 
 ...{ 
 勾选但不移动的处理#region 勾选但不移动的处理(如果用户勾选了该项,但是并没有移动程序的位置,则进行该项判断)
 //2012年1月31日0:27:44 解决思路: 
 //先判断ini文件是否存在,如果是第一次启动程序或ini文件丢失,则无ini文件, 
 //则没有上次保存的ini配置信息,不进行读取操作,否则 
 //先从ini文件中读取上次设定的x,y的坐标值,作为old_x,old_y。再将新的坐标值与旧的 
 //坐标值进行比较,如果窗体移动了,则比较后不同,进行写入ini操作,否则不写入 
 
 if (File.Exists(pathbase + "CnClock.ini")) 
 ...{ 
 try 
 ...{ 
 StreamReader sr = new StreamReader(pathbase + "CnClock.ini", Encoding.GetEncoding("gb2312")); 
 if (sr.Peek() >= 0) 
 ...{ 
 old_x = Convert.ToInt32(sr.ReadLine()); 
 old_y = Convert.ToInt32(sr.ReadLine()); 
 } 
 sr.Close(); 
 } 
 catch (Exception ex) 
 ...{ 
 MessageBox.Show(ex.Message.ToString()); 
 } 
 } 
 #endregion 
 //2012年1月30日22:34:43,又想到一个新问题:如果用户勾选了“吸附桌面”项后,没有移动该窗体的位置, 
 //这种情况下是否要判断一下新位置与原位置是否相同??? 经考虑,需设定! 
 //2012年1月31日0:21:04 设置完成,代码见 #勾选但不移动的处理 部分 
 
 //什么时候才会执行下面这句代码“yidong = false;” 呢? 
 //分析:在form_load时不会执行,只有当用户移动窗体后,再选中"吸附桌面"项后才会执行 
 //这句代码,所以这里才是控制什么时候将新的位置坐标写入ini文件的地方,在这句下面写相应代码 
 yidong = false; 
 
 
 //如果用户勾掉了“吸附桌面”选项,则窗体可以移动,待用户确定新位置后, 
 //如果用户不勾上“吸附桌面”菜单项,则不记录新位置坐标,否则将新位置的坐标写入ini配置文件中。 
 try 
 ...{ 
 //获取窗体移动后的坐标(_x,_y) 
 _x = this.Location.X; 
 _y = this.Location.Y; 
 //勾选但不移动的处理(部分代码) 
 xin_x = this.Location.X; 
 xin_y = this.Location.Y; 
 
 //相或,一真为真。即如果x不同或y不同或两个都不同,则说明窗体位置发生变化了 
 //须执行写入操作 
 //勾选但不移动的处理(部分代码) 
 if (!(xin_x == old_x) || !(xin_y == old_y)) 
 ...{ 
 StreamWriter sw = new StreamWriter(pathbase + "CnClock.ini", false, Encoding.GetEncoding("gb2312")); 
 sw.Flush(); 
 sw.WriteLine(_x); 
 sw.WriteLine(_y); 
 sw.Close(); 
 //新位置确认后给予提示 
 this.notifyIcon1.ShowBalloonTip(5, "CnClock提示", "新位置已设定!", ToolTipIcon.Info); 
 } 
 } 
 catch (Exception ex) 
 ...{ 
 MessageBox.Show(ex.Message.ToString()); 
 } 
 } 
 else 
 ...{ 
 yidong = true; 
 } 
 }
 
 
 
 设置开机自启动功能:

 
 
  

//设置开机启动功能 
 private void 开机启动ToolStripMenuItem_CheckStateChanged(object sender, EventArgs e) 
 ...{ 
 /*设计思路: 2012年1月31日16:00:47完成 
 * 默认开机启动,则在form_load中先执行一下设置autorun方法。 
 * 用户勾掉“开机启动”项后,则取消autorun,用户勾选“开机启动”项后,则设置autorun。 
 */ 
 //初始为开机启动,则isautorun初始为true,当用户点击该项后,isautorun为false,不开机启动。 
 isautorun = !isautorun; 
 if (isautorun == true) 
 ...{ 
 //isautorun为true,开机启动 
 auToRun.SetAutoRun(Application.ExecutablePath, true); 
 //设置为开机启动后给予提示 
 this.notifyIcon1.ShowBalloonTip(5, "CnClock提示", "开机启动已设定!", ToolTipIcon.Info); 
 } 
 else 
 ...{ 
 //isautorun为false,开机不启动 
 auToRun.SetAutoRun(Application.ExecutablePath, false); 
 //设置为开机不启动后给予提示 
 this.notifyIcon1.ShowBalloonTip(5, "CnClock提示", "已关闭开机启动!", ToolTipIcon.Info); 
 } 
 }
 
 
 
 
程序下载地址:CnClock1.0版:http://dl.dbank.com/c0qbry08qv
            CnClock2.0版:http://dl.dbank.com/c0m78h7dty
            如果以上页面无法下载可到下面页面下载:http://www.kuaipan.cn/index.php?ac=file&oid=5028779638390791
 
 
说明:两个版本的区别是1.0版是方形显示的,2.0版是条形显示的(见文首图片)。
 
该程序需要.net Framework2.0或以上版本支持。

A small problem discovered so far:


When the program chooses whether to support startup, the registry must be operated. If the user's computer is equipped with management software such as 360 Security Guard or QQ Computer Manager, a prompt message will pop up. If the user chooses not to allow registry operations, the program will pop up an exception prompt, and the registry information will not be written, but the correct bubble prompt information will pop up. This place still needs to be modified.

For more CnClock desktop clock-Winform applet development related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn