基本信息
源码名称:C#关机长老程序+源码免费下载.zip
源码大小:0.14M
文件格式:.zip
开发语言:C#
更新时间:2019-09-23
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
namespace ElderOff
{
public partial class Form1 : Form
{
private string _cmdState = "nothing";
private int _countTime;
private int _goTime;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
notifyIcon1.Icon = Icon;
textBox1.Text = DateTime.Now.ToString();
numericUpDown1.Maximum = 23;
numericUpDown2.Maximum = 59;
numericUpDown3.Maximum = 59;
numericUpDown4.Maximum = 23;
numericUpDown5.Maximum = 59;
numericUpDown6.Maximum = 59;
comboBox1.Text = DateTime.Now.Month.ToString();
comboBox2.Text = DateTime.Now.Day.ToString();
numericUpDown1.Value = DateTime.Now.Hour;
numericUpDown2.Value = DateTime.Now.Minute;
numericUpDown3.Value = DateTime.Now.Second;
numericUpDown4.Enabled = false;
numericUpDown5.Enabled = false;
numericUpDown6.Enabled = false;
timer1.Interval = 1000;
timer1.Enabled = true;
timer2.Interval = 500;
timer2.Enabled = true;
textBox2.Enabled = false;
for (int i = 1; i < 13; i )
{
comboBox1.Items.Add(i);
}
for (int i = 1; i < 32; i )
{
comboBox2.Items.Add(i);
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
numericUpDown4.Enabled = false;
numericUpDown5.Enabled = false;
numericUpDown6.Enabled = false;
comboBox1.Enabled = true;
comboBox2.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
numericUpDown3.Enabled = true;
numericUpDown1.Focus();
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
numericUpDown4.Enabled = true;
numericUpDown5.Enabled = true;
numericUpDown6.Enabled = true;
numericUpDown1.Enabled = true;
comboBox1.Enabled = false;
comboBox2.Enabled = false;
numericUpDown1.Enabled = false;
numericUpDown2.Enabled = false;
numericUpDown3.Enabled = false;
numericUpDown4.Focus();
}
}
private void notifyShow() //显示托盘
{
Show();
ShowInTaskbar = true;
WindowState = FormWindowState.Normal;
}
private void notifyHide() //隐藏托盘
{
Hide();
ShowInTaskbar = false;
notifyIcon1.Visible = true;
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
notifyHide();
}
public void cancelPlan()
{
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
_cmdState = "nothing";
_goTime = 0;
textBox3.Text = "0";
MessageBox.Show("恭喜!任务已被取消!", "取消任务", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
private string f_getValue() //获取txt2的值,因为C#无法直接传递
{
return textBox2.Text;
}
private void button4_Click(object sender, EventArgs e)
{
if (button1.Enabled == false)
{
if (checkBox1.Enabled == false)
{
var f2 = new Form2();
f2.getvalue = f_getValue;
f2.ShowDialog();
Debug.Print(f2.BoolPwd.ToString());
if (f2.BoolPwd.ToString() == "1")
{
textBox2.Enabled = true;
checkBox1.Enabled = true;
cancelPlan();
}
f2.Close();
f2.Dispose();
}
else
{
cancelPlan();
}
}
else
{
MessageBox.Show("注意!请新建任务后再执行取消操作!", "新建任务", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now.ToString();
if (_cmdState != "nothing")
{
_goTime = 1;
if (_countTime - _goTime 1 < 0)
{
textBox3.Text = "0";
_cmdState = "nothing";
}
else
{
textBox3.Text = (_countTime - _goTime 1)/86400 "天 " (_countTime - _goTime 1)%86400/3600 "时 "
(_countTime - _goTime 1)%3600/60 "分 " (_countTime - _goTime 1)%60 "秒";
if (_countTime - _goTime 1 == 0)
{
var p1 = new ProcessStartInfo("shutdown.exe", _cmdState)
{
WindowStyle = ProcessWindowStyle.Hidden
};
//隐藏窗口
Process.Start(p1);
Application.ExitThread();
Application.Exit();
}
}
}
}
private void timeControl()
{
if (radioButton1.Checked)
{
DateTime startTime =
Convert.ToDateTime(DateTime.Now.Year.ToString() "/" comboBox1.Text "/" comboBox2.Text " "
numericUpDown1.Value ":" numericUpDown2.Value ":" numericUpDown3.Value);
TimeSpan endTime = startTime - DateTime.Now; //旧的时间减去新的时间
_countTime = endTime.Days*86400 endTime.Hours*3600 endTime.Minutes*60 endTime.Seconds; //转为秒
}
else
{
_countTime = decimal.ToInt32(numericUpDown4.Value)*3600 decimal.ToInt32(numericUpDown5.Value)*60
decimal.ToInt32(numericUpDown6.Value);
}
if (_countTime < 0)
{
MessageBox.Show("抱歉!您输入的时间已经过期,请重新输入!", "时间有误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
if (checkBox1.Checked == (textBox2.Text != ""))
{
textBox2.Enabled = false;
checkBox1.Enabled = false;
}
_goTime = 0;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
}
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
try
{
int n = int.Parse(comboBox1.Text);
if (n < 1 || n > 12)
comboBox1.Text = DateTime.Now.Month.ToString();
}
catch (Exception)
{
comboBox1.Text = DateTime.Now.Month.ToString();
}
}
private void comboBox2_TextChanged(object sender, EventArgs e)
{
try
{
int n = int.Parse(comboBox2.Text);
if (n < 1 || n > 31)
{
comboBox2.Text = DateTime.Now.Day.ToString();
}
else
{
if (comboBox1.Text == "2")
{
if (DateTime.IsLeapYear(DateTime.Now.Year)) //如果是闰年二月
{
if (Convert.ToInt32(comboBox2.Text) > 28)
comboBox2.Text = "28";
}
else
{
if (Convert.ToInt32(comboBox2.Text) > 29)
comboBox2.Text = "29";
}
}
else if (comboBox1.Text == "4" || comboBox1.Text == "6" || comboBox1.Text == "9" ||
comboBox1.Text == "11")
{
if (Convert.ToInt32(comboBox2.Text) > 30)
comboBox2.Text = "30";
}
}
}
catch (Exception)
{
comboBox2.Text = DateTime.Now.Day.ToString();
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
notifyIcon1.Icon = null;
notifyIcon1.Visible = false;
Application.Exit();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
textBox2.Enabled = true;
textBox2.Focus();
}
else
{
textBox2.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
timeControl();
_cmdState = "-s -f -t 0"; //关机
label4.Text = "剩余关机时间";
}
private void button2_Click(object sender, EventArgs e)
{
timeControl();
_cmdState = "-l"; //注销
label4.Text = "剩余注销时间";
}
private void button3_Click(object sender, EventArgs e)
{
timeControl();
_cmdState = "-r -f -t 0"; // 重启
label4.Text = "剩余重启时间";
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
notifyShow();
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
notifyShow();
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
notifyHide();
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
Process.Start("http://www.ibipin.com");
}
private void toolStripMenuItem4_Click(object sender, EventArgs e)
{
notifyHide();
Application.Exit();
}
private void timer2_Tick(object sender, EventArgs e)
{
}
}
}