欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#關機小程序源碼

 更新時間:2012年10月03日 19:43:34   作者:  
這是用所學習的C#做的一個關機小程序,功能不多,只是為了練手,需要的朋友可以參考下
下面是運行的效果圖



核心代碼:

復制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/*
*
* 整理:張曉天
* Q Q:977602650
* 日期:2012-03-29
*
*/
namespace ExitComputer
{
public partial class Form1 : Form
{
int goTime = 0;//程序運行時間
string cmd = null;//寫入shutdown的命令
int countTime = 0;//到程序執(zhí)行的時間
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 窗體加載事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
nfiPic.Icon = this.Icon;//指定系統的圖標
label1.Text = DateTime.Now.ToString("yyyy年 MM月 dd日 HH :mm :ss");//系統時間
nudHour.Maximum = 23;
nudMinutes.Maximum = 59;
nudSecond.Maximum = 59;//指定控件的最大值
cboMonth.Text = DateTime.Now.Month.ToString();
cboDay.Text = DateTime.Now.Day.ToString();
nudHour.Value = DateTime.Now.Hour;
nudMinutes.Value = DateTime.Now.Minute;
nudSecond.Value = DateTime.Now.Second;//指定控件的值
//指定時間控件發(fā)生的頻率
tmrTime.Interval = 1000;
tmrTime.Enabled = true;
//為月和日賦值
for (int i = 1; i < 13; i++)
{
cboMonth.Items.Add(i);
}
for (int i = 1; i < 32; i++)
{
cboDay.Items.Add(i);
}
//指定不可用的控件
cboMonth.Enabled = false;
cboDay.Enabled = false;
nudHour.Enabled = false;
nudMinutes.Enabled = false;
nudSecond.Enabled = false;
btnExit.Enabled = false;
}
//定時的屬性改寫時事件
private void chkTiming_CheckedChanged(object sender, EventArgs e)
{
if (chkTiming.Checked == true)
{
cboMonth.Enabled = true;
cboDay.Enabled = true;
nudHour.Enabled = true;
nudMinutes.Enabled = true;
nudSecond.Enabled = true;
}
else
{
cboMonth.Enabled = false;
cboDay.Enabled = false;
nudHour.Enabled = false;
nudMinutes.Enabled = false;
nudSecond.Enabled = false;
}
}
/// <summary>
/// 顯示窗體
/// </summary>
private void windowShow()
{
this.Show();
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
}
//重寫事件實現氣泡提示
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (WindowState == FormWindowState.Minimized)
{
nfiPic.ShowBalloonTip(30);
}
}
/// <summary>
/// 隱藏托盤
/// </summary>
private void windowHide()
{
this.Hide();
this.ShowInTaskbar = false;
nfiPic.Visible = true;
nfiPic.ShowBalloonTip(30);
}
//最小化窗體時的事件
private void Form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
this.windowHide();
}
//鼠標雙擊托盤圖標時的事件
private void nfiPic_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.windowShow();
}
//保證選擇的月份是正確的
private void cboMonth_TextChanged(object sender, EventArgs e)
{
try
{
int temp1 = int.Parse(cboMonth.Text);
int temp = int.Parse(cboDay.Text);
if (temp1 < 1 || temp1 > 12)
{
cboMonth.Text = DateTime.Now.Month.ToString();
}
if (cboMonth.Text == "2")
{
if (DateTime.IsLeapYear(DateTime.Now.Year) == true)//判斷今年是否為閏年
{
if (temp > 28)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
else if (temp > 29)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
else if (cboMonth.Text == "4" || cboMonth.Text == "6" || cboMonth.Text == "9" || cboMonth.Text == "11")
{
if (temp > 30)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
}
catch (Exception)
{
cboMonth.Text = DateTime.Now.Month.ToString();
}
}
//保證選擇的天數是正確的
private void cboDay_TextChanged(object sender, EventArgs e)
{
try
{
int temp = int.Parse(cboDay.Text);
if (temp < 1 || temp > 31)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
//判斷月份
if (cboMonth.Text == "2")
{
if (DateTime.IsLeapYear(DateTime.Now.Year) == true)//判斷今年是否為閏年
{
if (temp > 28)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
else if (temp > 29)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
else if (cboMonth.Text == "4" || cboMonth.Text == "6" || cboMonth.Text == "9" || cboMonth.Text == "11")
{
if (temp > 30)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
}
catch (Exception)
{
cboDay.Text = DateTime.Now.Day.ToString();
}
}
//程序執(zhí)行時給CountTime賦的值
private bool timeControl()
{
if (chkTiming.Checked == true)
{
DateTime startTime = Convert.ToDateTime(DateTime.Now.Year.ToString() + "/" + cboMonth.Text + "/" +
cboDay.Text + " " + nudHour.Value.ToString() + ":" + nudMinutes.Value.ToString() + ":" + nudSecond.Value.ToString());
TimeSpan endtime = startTime - DateTime.Now;
countTime = endtime.Days * 86400 + endtime.Hours * 3600 + endtime.Minutes * 60 + endtime.Seconds;
}
if (countTime < 0)
{
MessageBox.Show("對不起!您選擇的時間有誤!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//讓窗體回到初始化時的狀態(tài)
chkTiming.Enabled = true;
btnLogout.Enabled = true;
btnOver.Enabled = true;
btnAgain.Enabled = true;
btnExit.Enabled = false;
tmrTime.Enabled = false;
return false;
}
tmrTime.Enabled = true;
return true;
}
//時間控件每次發(fā)生的事件
private void tmrTime_Tick(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("yyyy年 MM月 dd日 HH :mm :ss");
if (cmd != null)
{
goTime += 1;
if (countTime - goTime + 5 < 0)
{
txtRemind.Text = "0";
cmd = null;
}
else
{
//在提示文本中顯示的內容
int temp = countTime - goTime + 1;
txtRemind.Text = temp / 86400 + "天 " + temp % 86400 / 3600 + "時 " + temp % 3600 / 60 + "分 " + temp % 60 + "秒 ";
if (countTime - goTime + 1 == 0) //判斷時間是否到了
{
System.Diagnostics.ProcessStartInfo p1 = new System.Diagnostics.ProcessStartInfo("shutdown.exe", cmd);
p1.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process.Start(p1);
Application.ExitThread();
Application.Exit();//程序結束
}
}
}
}
/// <summary>
/// 定時關機事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOver_Click(object sender, EventArgs e)
{
if (!timeControl()) return;
cmd = "-s -t 0";
lblRemind.Text = "剩余時間";
chkTiming.Checked = false;
chkTiming.Enabled = false;
btnExit.Enabled = true;
Allow();
}
/// <summary>
/// 重啟事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAgain_Click(object sender, EventArgs e)
{
if (!timeControl()) return;
cmd = "-r -t 0";
lblRemind.Text = "剩余時間";
chkTiming.Checked = false;
chkTiming.Enabled = false;
btnExit.Enabled = true;
Allow();
}
private void btnLogout_Click(object sender, EventArgs e)
{
if (!timeControl()) return;
cmd = "-l";
lblRemind.Text = "剩余時間";
chkTiming.Checked = false;
chkTiming.Enabled = false;
btnExit.Enabled = true;
Allow();
}
private void tsmiShow_Click(object sender, EventArgs e)
{
this.windowShow();
}
private void tsmiExit_Click(object sender, EventArgs e)
{
this.Dispose();
}
/// <summary>
/// 單擊取消發(fā)生的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExit_Click(object sender, EventArgs e)
{
btnLogout.Enabled = true;
btnOver.Enabled = true;
btnAgain.Enabled = true;
btnExit.Enabled = false;
cmd = null;
goTime = 0;
countTime = 0;
txtRemind.Text = "0";
lblRemind.Text = "關機提示";
chkTiming.Enabled = true;
MessageBox.Show("任務已被成功取消", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
/// <summary>
/// 提醒事件
/// </summary>
public void Allow()
{
DialogResult result;
result = MessageBox.Show("程序將自動最小化到托盤", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
this.windowHide();
}
}
}
}

源碼打包下載

相關文章

  • 超炫酷的WPF實現Loading控件效果

    超炫酷的WPF實現Loading控件效果

    這篇文章主要介紹了超炫酷的WPF實現Loading控件效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2015-11-11
  • 解析C# 程序結構

    解析C# 程序結構

    在我們學習 C# 編程語言的基礎構件塊之前,讓我們先看一下 C# 的最小的程序結構,以便作為接下來章節(jié)的參考
    2021-07-07
  • c# wpf如何附加依賴項屬性

    c# wpf如何附加依賴項屬性

    這篇文章主要介紹了c# wpf如何附加依賴項屬性,幫助大家更好的理解和學習使用c#,感興趣的朋友可以了解下
    2021-03-03
  • C# winform中窗口關閉按鈕的隱藏與禁用詳解

    C# winform中窗口關閉按鈕的隱藏與禁用詳解

    這篇文章主要介紹了C# winform中窗口關閉按鈕的隱藏與禁用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • 詳解c# 委托鏈

    詳解c# 委托鏈

    這篇文章主要介紹了c# 委托鏈的相關資料,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-07-07
  • C#表達式樹Expression基礎講解

    C#表達式樹Expression基礎講解

    這篇文章介紹了C#表達式樹Expression和基本用法,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-12-12
  • Unity實現QQ列表折疊菜單

    Unity實現QQ列表折疊菜單

    這篇文章主要為大家詳細介紹了Unity實現QQ列表折疊菜單,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • ftp服務器搭建部署與C#實現ftp文件的上傳的示例

    ftp服務器搭建部署與C#實現ftp文件的上傳的示例

    本文主要介紹了ftp服務器搭建部署與C#實現ftp文件的上傳的示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-07-07
  • C#結合數據庫實現驗證識別ID卡內容的方法

    C#結合數據庫實現驗證識別ID卡內容的方法

    這篇文章主要介紹了C#結合數據庫實現驗證識別ID卡內容的方法,非常實用的功能,需要的朋友可以參考下
    2014-07-07
  • C#實現QQ窗口抖動效果

    C#實現QQ窗口抖動效果

    這篇文章主要為大家詳細介紹了C#實現QQ窗口抖動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-11-11

最新評論