⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 Csharp编写的关于智能手机(smartphone)闹钟程序
💻 CS
📖 第 1 页 / 共 2 页
字号:

			h = DateTime.Now .Hour;
			m = DateTime.Now .Minute;
			s = DateTime.Now .Second;

			if(m<10)
				ms="0"+m.ToString ();
			else
				ms=m.ToString ();

			if(s<10)
				ss="0"+s.ToString ();
			else
				ss=s.ToString ();

			if(h<10)
				hs = "0"+h.ToString ();
			else
				hs = h.ToString ();


			temp = hs + ":" + ms + ":" + ss; 
			

			if(ms=="00" && ss == "00" && SoundH == true)
			{
				//Common.PlaySound ("SoundH.wav",0,0x05);
				ThreadSound = new Thread (new ThreadStart (PlaySoundH));
				ThreadSound.Start ();
			}
			if(ms == "30" && ss == "00" && SoundHH == true )
			{
				//Common.PlaySound ("SoundHH.wav",0,0x05);
				ThreadSound = new Thread (new ThreadStart (PlaySoundHH));
				ThreadSound.Start ();
			}
			MainLabel.Text = temp ;

			
		}

		#endregion


		//****************************************************************************
		//读取背景文件设置
		//****************************************************************************
		private void GetLabelPoint()
		{
			string skinname = BmpFileStr ;
			Ini SkinIni = new Ini (@"Skin\Skin.ini");
			LabelPoint.X = Convert.ToInt32 (SkinIni.IniReadValue (BmpFileStr,"pX"));
			LabelPoint.Y = Convert.ToInt32 (SkinIni.IniReadValue (BmpFileStr,"pY"));
			SkinIni = null;
		}


        
		//*****************************************************************************
		//显示渐变色彩的数字Label
		//*****************************************************************************
		private void ShowLabel()
		{
			MainLabel = new ClockLabel ();
			MainLabel.Size = new Size (110,25);
			MainLabel.Location = LabelPoint;
			MainLabel.ForeColor = Color.FromName (FontColor) ;
			MainLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight ;
			MainLabel.Font = new System.Drawing.Font("Arial", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			MainLabel.GradientColorOne = Color.FromName (LabelColorOne) ;
			MainLabel.GradientColorTwo = Color.FromName (LabelColorTwo);
			MainLabel.BorderStyle = System.Windows.Forms.Border3DStyle.Adjust ;
			this.Controls .Add (this.MainLabel );
		}



		private void MainForm_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(e.Button == MouseButtons.Left) 
			{ 
				Point mousePos = Control.MousePosition; 
				mousePos.Offset(m_pOffset.X, m_pOffset.Y); 
				Location = mousePos; 
				xPos = mousePos.X ;
				yPos = mousePos.Y ;
				if(xPos<0)
					xPos = 0 ;
				if(yPos<0)
					yPos = 0 ;
				this.LocationMain .X = xPos;
				this.LocationMain .Y = yPos;

			}//响应鼠标移动,并移动窗口
		}

		private void MainForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			m_pOffset = new Point(-e.X, -e.Y);//记录鼠标位置
		}



		//实现窗口的淡入效果
		private void timerShow_Tick(object sender, System.EventArgs e)
		{
			this.Opacity = WinShow ;
			WinShow += 0.1;
			if(WinShow == 1)
			{
				this.timerShow.Stop ();
			}
		}

		private void menuItemExit_Click(object sender, System.EventArgs e)
		{
			this.timerClock .Dispose ();
			this.Close ();
		}


		//改变窗口背景、大小
		private void RePaint()
		{
			Bitmap bmp = new Bitmap (BmpFileStr);
			this.BackgroundImage = bmp ;
			this.Size = new Size (bmp.Width ,bmp.Height );
			this.GetLabelPoint ();
			this.MainLabel .Location = LabelPoint;
		}


		#region  *******************  防止程序多次执行  **************************
		public abstract class OneInstance 
		{ 
			/// <summary> 
			/// 用来判断一个指定的程序是否正在运行 
			/// </summary> 
			/// <param name="appId">程序名称,长一点比较好,防止有重复</param> 
			/// <returns>如果程序是第一次运行返回True,否则返回False</returns> 
			public static bool IsFirst(string appId) 
			{ 
				bool ret=false; 
				if(OpenMutex(0x1F0001,0,appId)==IntPtr.Zero) 
				{ 
					CreateMutex(IntPtr.Zero,0,appId); 
					ret=true; 
				} 
				return ret; 
			} 

			[DllImport("Kernel32.dll",CharSet=CharSet.Auto)] 
			private static extern IntPtr OpenMutex( 
				uint dwDesiredAccess,  // access 
				int bInheritHandle,    // inheritance option 
				string lpName          // object name 
				); 

			[DllImport("Kernel32.dll",CharSet=CharSet.Auto)] 
			private static extern IntPtr CreateMutex( 
				IntPtr lpMutexAttributes,  // SD 
				int bInitialOwner,                       // initial owner 
				string lpName                            // object name 
				); 
		}

		#endregion

		private void CheckTask()
		{
			Task task = new Task ();

			int sec = task.CheckAlarm ();
			

			if(sec!=0)
			{
				this.timerAlarm .Interval = sec * 1000 ;
				this.timerAlarm .Start ();
			}
		}

		private void timerAlarm_Tick(object sender, System.EventArgs e)
		{
			this.timerAlarm .Stop ();
			Task task = new Task ();
			task.Alarm ();
			
		}

		private void OnMyMenu(object sender, System.EventArgs e)
		{
			NiceMenu item = (NiceMenu)sender;

			if (item.Text == "退出")
			{
				this.timerClock .Dispose ();
				this.Close ();
			}

			if(item.Text == "程序设置")
			{
				SetupForm Setup = new SetupForm ();
				DialogResult result = Setup.ShowDialog ();
				if(Setup.BackColor1 != "")
				{
					this.LabelColorOne = Setup.BackColor1 ;
					this.LabelColorTwo = Setup.BackColor2 ;
					this.FontColor = Setup.FontColor ;
					this.MainLabel .ForeColor = Color.FromName (this.FontColor) ;
					this.MainLabel .GradientColorOne = Color.FromName (this.LabelColorOne );
					this.MainLabel .GradientColorTwo = Color.FromName (this.LabelColorTwo );
					this.MainLabel .Invalidate ();

					this.SoundH = Setup.SoundH ;
					this.SoundHH = Setup.SoundHH ;
				}

				if(Setup.SkinFile != "")
				{
					this.BmpFileStr = Setup.SkinFile ;
					this.RePaint ();
				}
			}

			if(item.Text == "定时任务")
			{
				SetAlarm alarmDlg = new SetAlarm ();
				alarmDlg.ShowDialog ();

				this.CheckTask ();
			}

			if(item.Text == "关闭计算机")
			{
				if(MessageBox.Show ("您确定要关闭计算机吗? ", "关闭计算机",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)  
				{ 
					Common.DoExitWin (Common.EWX_SHUTDOWN );
				} 
			}

			if(item.Text == "重新启动计算机")
			{
				if(MessageBox.Show ("您确定要重新启动计算机吗? ", "重新启动计算机",MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)  
				{ 
					Common.DoExitWin (Common.EWX_REBOOT );
				} 
			}


			if(item.Text == "关于")
			{
				AboutForm aboutDlg = new AboutForm ();
				aboutDlg.ShowDialog ();

				/*TaskbarNotifier Notifier=new TaskbarNotifier();
				Notifier.SetBackgroundBitmap(new Bitmap("skin2.bmp"),Color.FromArgb(255,0,255));
				Notifier.SetCloseBitmap(new Bitmap("close2.bmp"),Color.FromArgb(255,0,255),new Point(300,74));
				Notifier.TitleRectangle=new Rectangle(123,80,176,16);
				Notifier.ContentRectangle=new Rectangle(116,97,197,22);
				Notifier.AutoHide = false ;
				Notifier.Show ("闹钟","ABOUT ME !!!",500,3000,500);*/
			}

			if(item.Text == "弹出/关闭光驱")
			{
				if(!DoorOpened)
					Common.mciSendString ("set cdaudio door open","",0,0);
				if(DoorOpened)
					Common.mciSendString ("set cdaudio door closed","",0,0);

				DoorOpened = !DoorOpened;
			}

		}


		private void PlaySoundH()
		{
			Common.PlaySound ("SoundH.wav",0,0x05);
		}

		private void PlaySoundHH()
		{
			Common.PlaySound ("SoundHH.wav",0,0x05);
		}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -