📄 mainform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading ;
namespace MyClock
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components = null;
private string BmpFileStr;//背景位图路径
private Bitmap bgBmp;//背景位图
private System.Windows.Forms.Timer timerClock;
private ClockLabel MainLabel;//时钟Label
private Point LabelPoint = new Point (0,0);//数字LABEL位置
private Point LocationMain = new Point (0,0);//主窗口位置
private bool SoundH,SoundHH;//整点报时,半点报时
private bool DoorOpened = false ; //光驱门是否打开
private string FontColor , LabelColorOne , LabelColorTwo;//字体颜色、背景颜色一、二
private Point m_pOffset;//鼠标偏移
private int xPos,yPos;//鼠标位置
private System.Windows.Forms.Timer timerShow;//计时器
private System.Windows.Forms.ContextMenu popMenu;//右键菜单
private System.Windows.Forms.MenuItem menuItemSetup;
private System.Windows.Forms.MenuItem menuItemExit;//任务栏图标
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItemAbout;
private System.Windows.Forms.MenuItem menuItemAlarm;
private System.Windows.Forms.Timer timerAlarm;
private System.Windows.Forms.MenuItem menuItemShutDown;
private System.Windows.Forms.MenuItem menuItemReboot;
private System.Windows.Forms.MenuItem menuItemCdrom;
private double WinShow = 0;//用于窗口淡入效果的变量
private NiceMenu myMenu ;
private Thread ThreadSound;
public MainForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
//BmpFileStr = @"Skin\巴布豆.bmp";
this.Opacity = 0;//初始时窗口不可见
LoadData();//载入配置文件
GetLabelPoint();//读取数字LABEL显示的位置
bgBmp = new Bitmap (BmpFileStr);
ShowLabel();//显示数字LABEL
this.timerShow .Start ();//执行窗口淡入效果
this.timerClock .Start ();
this.Location = LocationMain ;//移动窗口至上次记录的位置
CheckTask();
myMenu = new NiceMenu ();
myMenu.UpdateMenu (this.ContextMenu ,new NiceMenuClickEvent (OnMyMenu));
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timerClock = new System.Windows.Forms.Timer(this.components);
this.timerShow = new System.Windows.Forms.Timer(this.components);
this.popMenu = new System.Windows.Forms.ContextMenu();
this.menuItemSetup = new System.Windows.Forms.MenuItem();
this.menuItemAlarm = new System.Windows.Forms.MenuItem();
this.menuItemCdrom = new System.Windows.Forms.MenuItem();
this.menuItemReboot = new System.Windows.Forms.MenuItem();
this.menuItemShutDown = new System.Windows.Forms.MenuItem();
this.menuItemAbout = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItemExit = new System.Windows.Forms.MenuItem();
this.timerAlarm = new System.Windows.Forms.Timer(this.components);
//
// timerClock
//
this.timerClock.Interval = 1000;
this.timerClock.Tick += new System.EventHandler(this.timerClock_Tick);
//
// timerShow
//
this.timerShow.Tick += new System.EventHandler(this.timerShow_Tick);
//
// popMenu
//
this.popMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemSetup,
this.menuItemAlarm,
this.menuItemCdrom,
this.menuItemReboot,
this.menuItemShutDown,
this.menuItemAbout,
this.menuItem1,
this.menuItemExit});
//
// menuItemSetup
//
this.menuItemSetup.Index = 0;
this.menuItemSetup.Text = "程序设置";
//
// menuItemAlarm
//
this.menuItemAlarm.Index = 1;
this.menuItemAlarm.Text = "定时任务";
//
// menuItemCdrom
//
this.menuItemCdrom.Index = 2;
this.menuItemCdrom.Text = "弹出/关闭光驱";
//
// menuItemReboot
//
this.menuItemReboot.Index = 3;
this.menuItemReboot.Text = "重新启动计算机";
//
// menuItemShutDown
//
this.menuItemShutDown.Index = 4;
this.menuItemShutDown.Text = "关闭计算机";
//
// menuItemAbout
//
this.menuItemAbout.Index = 5;
this.menuItemAbout.Text = "关于";
//
// menuItem1
//
this.menuItem1.Index = 6;
this.menuItem1.Text = "-";
//
// menuItemExit
//
this.menuItemExit.Index = 7;
this.menuItemExit.Text = "退出";
//
// timerAlarm
//
this.timerAlarm.Tick += new System.EventHandler(this.timerAlarm_Tick);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(120, -9);
this.ContextMenu = this.popMenu;
this.Cursor = System.Windows.Forms.Cursors.SizeAll;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "MainForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.TopMost = true;
this.TransparencyKey = System.Drawing.Color.Blue;
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseDown);
this.Load += new System.EventHandler(this.MainForm_Load);
this.Closed += new System.EventHandler(this.MainForm_Closed);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseMove);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//防止程序多次运行
if(!OneInstance.IsFirst("MyClock"))
{
MessageBox.Show ("玉兰时钟已经在运行中!!");
return;
}
Application.Run(new MainForm());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
this.BackgroundImage = bgBmp;//设置窗口背景
this.Size = new Size (bgBmp.Width ,bgBmp.Height );//设置窗口大小
this.Location = LocationMain;
}
#region ******************************** 记录(读取)程序设置 ******************************
private void SaveData()
{
string path = Application.StartupPath ;
Ini ini = new Ini(path+"\\Set.ini");
ini.IniWriteValue ("Main","BmpFileStr",BmpFileStr);
ini.IniWriteValue ("Main","LabelColorOne",LabelColorOne);
ini.IniWriteValue ("Main","LabelColorTwo",LabelColorTwo);
ini.IniWriteValue ("Main","FontColor",FontColor);
ini.IniWriteValue ("Main","LocationX",LocationMain.X.ToString () );
ini.IniWriteValue ("Main","LocationY",LocationMain.Y.ToString ());
}
private void LoadData()
{
string path = Application.StartupPath ;
Ini ini = new Ini(path+"\\Set.ini");
BmpFileStr = ini.IniReadValue ("Main","BmpFileStr");
FontColor = ini.IniReadValue ("Main","FontColor");
LabelColorOne = ini.IniReadValue ("Main","LabelColorOne");
LabelColorTwo = ini.IniReadValue ("Main","LabelColorTwo");
LocationMain.X = Convert.ToInt32 (ini.IniReadValue ("Main","LocationX"));
LocationMain.Y = Convert.ToInt32 (ini.IniReadValue ("Main","LocationY"));
SoundH = Convert.ToBoolean (ini.IniReadValue ("Main","SoundH"));
SoundHH = Convert.ToBoolean (ini.IniReadValue ("Main","SoundHH"));
}
#endregion
private void MainForm_Closed(object sender, System.EventArgs e)
{
SaveData();//保存程序设置
}
#region ****************************** 取系统时间并显示 *********************************
private void timerClock_Tick(object sender, System.EventArgs e)
{
int h,m,s;
string temp,hs,ms,ss;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -