zoukankan      html  css  js  c++  java
  • 自己玩的定时关机小软件

    这些天晚上总是听着音乐睡觉,可是电脑不能开一晚上啊 ,就想下载个定时关机的

    可没找到自己喜欢的,就自己写了一个用来玩的定时关机的

    功能比较单一,自己用不错。呵呵

    主要代码如下:

    //关机程序调用 cmd.exe 加传参
    Process.Start("cmd.exe""/c shutdown /s /t 10");

    //计算时间间隔 TimeSpan
    TimeSpan ts = new TimeSpan(dtpSetTime.Value.Ticks - DateTime.Now.Ticks);

     完整代码如下:

    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;
    using System.Runtime.InteropServices;
    using System.Diagnostics;

    namespace 定时关机
    {
        
    public partial class frmMain : Form
        {
            
    public frmMain()
            {
                InitializeComponent();
            }

            
    private void timer1_Tick(object sender, EventArgs e)
            {
                
    //时间到了
                if (dtpSetTime.Value.ToString() == DateTime.Now.ToString())
                {
                    
    //关机
                    Process.Start("cmd.exe""/c shutdown /s /t 10");
                    timer1.Enabled 
    = false;

                    
    //
                    dtpSetTime.Enabled = true;
                    btnDo.Text 
    = "倒计时开始";
                    btnExitClose.Enabled 
    = true;
                    
    return;
                }

                TimeSpan ts 
    = new TimeSpan(dtpSetTime.Value.Ticks - DateTime.Now.Ticks);

                lblInfo.Text 
    = "距离关机还剩 " + (int)ts.TotalHours + " 小时 " + ts.Minutes + " 分 " + ts.Seconds + " 秒 ";
            }

            
    private void Form1_Load(object sender, EventArgs e)
            {
                dtpSetTime.Value 
    = DateTime.Now;
            }

            
    private void btnStart_Click(object sender, EventArgs e)
            {
                
    //时间设置是否许可
                if (dtpSetTime.Value.Ticks <= DateTime.Now.Ticks)
                {
                    timer1.Enabled 
    = false;
                    MessageBox.Show(
    "不能设置比现在还早的时间!时间不能倒流哦!");
                    
    return;
                }

                
    if (!timer1.Enabled)
                {
                    timer1.Enabled 
    = true;
                    dtpSetTime.Enabled 
    = false;
                    btnDo.Text 
    = "点击停止倒计时";
                }
                
    else
                {
                    timer1.Enabled 
    = false;
                    dtpSetTime.Enabled 
    = true;
                    btnDo.Text 
    = "倒计时开始";
                }
            }

            
    private void btnExitClose_Click(object sender, EventArgs e)
            {
                Process.Start(
    "cmd.exe""/c shutdown /a");
            }
        }
    }
  • 相关阅读:
    javascript数组对象
    jquery、javascript实现(get、post两种方式)跨域解决方法
    js检查字符串的包含关系
    element——message消息提示
    js把mysql传过来的时间格式化为:0000-00-00 00:00:00
    beego orm操蛋问题:操作都需要主键
    element——message-box
    VUE.js全局变量的定义
    element el-upload组件获取文件名
    go遍历某个文件夹
  • 原文地址:https://www.cnblogs.com/heimirror/p/1396166.html
Copyright © 2011-2022 走看看