基本信息
源码名称:C# 自动关机 DEMO
源码大小:0.10M
文件格式:.rar
开发语言:C#
更新时间:2018-04-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
C#编写的自动关机简单Demo
namespace WindowsFormsApplication1
{
public partial class 关机 : Form
{
private DateTime end;
public 关机()
{
InitializeComponent();
yearLabel.Text = DateTime.Now.Year.ToString();
monthLabel.Text = DateTime.Now.Month.ToString();
dayLabel.Text = DateTime.Now.Day.ToString();
hourLabel.Text = DateTime.Now.Hour.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
shutdown();
}
public static void shutdown()
{
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 0");
}
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = end - DateTime.Now;
showArea.Text = "距离关机还有:" (end.Day - DateTime.Now.Day).ToString() "天 " (end.Hour - DateTime.Now.Hour).ToString() "小时 " (end.Minute - DateTime.Now.Minute).ToString() "分钟 ";
if (end.ToString() == DateTime.Now.ToString())
{
if (closeCheckBox.Checked == true)
{
if ((MessageBox.Show("时间到", "提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK))
{
shutdown();
}
else
{
timer1.Stop();
MessageBox.Show("已经取消", "提示");
}
}
else
shutdown();
}
}
private void button2_Click(object sender, EventArgs e)
{
end = new DateTime(Convert.ToInt16(yearLabel.Text), Convert.ToInt16(monthLabel.Text), Convert.ToInt16(dayLabel.Text), Convert.ToInt16(hourLabel.Text), Convert.ToInt16(minLabel.Text), 0);
timer1.Interval = 1000;
timer1.Enabled = true;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//
if ((MessageBox.Show("最小化至后台", "提示!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK))
{
e.Cancel = true;
this.Hide();
this.notifyIcon1.Text = "服务正在运行...";
this.notifyIcon1.ShowBalloonTip(1000, "提示", "服务正在运行...", System.Windows.Forms.ToolTipIcon.Info);
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
if (this.Visible)
{
this.Hide();
}
else
this.Show();
}
private void 关机_Load(object sender, EventArgs e)
{
}
}
}