基本信息
源码名称:C# 定时关机、重启、注销 工具源码
源码大小:0.07M
文件格式:.rar
开发语言:C#
更新时间:2018-02-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace shutdown
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//默认状态下,DateTimePicker控件只显示日期,如果想更改为显示时间,或日期 时间,需要做以下设置:
//控制日期或时间的显示格式
dateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm:ss";
//使用自定义格式
dateTimePicker1.Format = DateTimePickerFormat.Custom;
//时间控件的启用
dateTimePicker1.ShowUpDown = true;
dateTimePicker1.Value = DateTime.Now;
radioButton1.Checked = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
private void button2_Click(object sender, EventArgs e)
{
Process.Start("c:/windows/system32/shutdown.exe", "-a ");
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if(DateTime.Now.ToString("yyyy-MM-dd HH:mm").CompareTo(dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm"))>0)
{
MessageBox.Show("关机时间小于当前时间");
return;
}
TimeSpan timeSpan=dateTimePicker1.Value-Convert.ToDateTime( DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
int sec = Convert.ToInt32(timeSpan.TotalSeconds);
int min = Convert.ToInt32(timeSpan.TotalMinutes);
int hou = Convert.ToInt32(timeSpan.TotalHours);
DialogResult result;
if (radioButton1.Checked == true)
{
result = MessageBox.Show(hou " 小时 " min % 60 " 分后关机?", "询问提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
else if (radioButton2.Checked == true)
{
result = MessageBox.Show(hou " 小时 " min % 60 " 分后重启?", "询问提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
else {
result = MessageBox.Show(hou " 小时 " min % 60 " 分后注销?", "询问提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
if (result == DialogResult.Cancel)
{
return;
}
if (radioButton1.Checked == true)
{
Process.Start("c:/windows/system32/shutdown.exe", "-s -t " Convert.ToInt32(timeSpan.TotalSeconds));
}
else if (radioButton2.Checked == true)
{
Process.Start("c:/windows/system32/shutdown.exe", "-r -t " Convert.ToInt32(timeSpan.TotalSeconds));
}
else
{
Process.Start("c:/windows/system32/shutdown.exe", "-l -t " Convert.ToInt32(timeSpan.TotalSeconds));
}
}
}
}