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");
            }
        }
    }
  • 相关阅读:
    Flask中路由系统、Flask的参数及app的配置
    linux之master和minion
    linux之docker学习
    项目的发布(nginx、uwsgi、django、virtualenv、supervisor)
    Linux下安装和使用nginx
    linux下主从同步和redis的用法
    论图像识别的预处理技术
    图像技术分析 图像编辑器核心技术
    C++ Primer 第九章 顺序容器
    图像灰度化公式 颜色空间用途说明
  • 原文地址:https://www.cnblogs.com/heimirror/p/1396166.html
Copyright © 2011-2022 走看看