C#窗口实现定时关机系统

本文实例为大家分享了C#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下

看一下运行之后的效果图

看代码

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;

namespace ShutDoneWindows
{
  public partial class ShutDone : Form
  {
    public ShutDone()
    {
      InitializeComponent();
    }

    private void menuItemExit_Click(object sender, EventArgs e)
    {
      Application.Exit();
    }

    private void ShutDone_Load(object sender, EventArgs e)
    {
      this.timer1.Start();
      DateTime DT = System.DateTime.Now;
      string dt = System.DateTime.Now.ToString();
      txtDatatime.Text = dt;
    }

    private void btnHide_Click(object sender, EventArgs e)
    {
      this.Hide();
      this.notifyIcon1.Visible = true;
    }

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
      this.Visible = true;
      this.WindowState = FormWindowState.Normal;
      this.notifyIcon1.Visible = false;
    }

    private void btnShutDone_Click(object sender, EventArgs e)
    {
      System.Diagnostics.Process.Start("cmd.exe", "/cshutdown -s -t 0");
    }

    private void btnReLogin_Click(object sender, EventArgs e)
    {
      System.Diagnostics.Process.Start("cmd.exe", "/logoff 0");
    }

    private void btnReBoot_Click(object sender, EventArgs e)
    {
      System.Diagnostics.Process.Start("cmd.exe", "/shutdown -r 0");
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      DateTime objDatetime = System.DateTime.Now;
      string cData = objDatetime.ToLongDateString();
      string cTime = objDatetime.ToLongTimeString();
      this.txtDatatime.Text = cData + "" + cTime;
      if (this.chkStrat.Checked == true)
      {
        int Y = this.dtpCurrentDate.Value.Year;
        int M = this.dtpCurrentDate.Value.Month;
        int D = this.dtpCurrentDate.Value.Day;
        int H = this.dtpCurrentTime.Value.Hour;
        int Min = this.dtpCurrentTime.Value.Minute;
        int S = this.dtpCurrentTime.Value.Second;
        objDatetime = new DateTime(Y, M, D, H, Min, S);
        System.TimeSpan remain = objDatetime - System.DateTime.Now;
        double time = remain.TotalSeconds;
        if (time < 0)
        {
          this.chkStrat.Checked = false;
          MessageBox.Show("设定的定时时间必须大于当前时间");
        }
        else
        {
          if (time < 60 && this.rbtnOneMinute.Checked == true)
          {
            AwokeForm aw = new AwokeForm();
            this.timer1.Stop();
            this.Hide();
            aw.Show();
          }
          if (time < 0 && this.rbtnNone.Checked == true)
          {
            System.Diagnostics.Process.Start("cmd.exe", "/cshutdown -s -t 0");

          }
        }

      }
    }

    private void chkStrat_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void rbtnOneMinute_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void rbtnNone_CheckedChanged(object sender, EventArgs e)
    {

    }
  }
}

窗口提醒的代码!

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;

namespace ShutDoneWindows
{
  public partial class AwokeForm : Form
  {
    public AwokeForm()
    {
      InitializeComponent();
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
      timer1.Stop();
      this.Close();
    }

    private void AwokeForm_Load(object sender, EventArgs e)
    {
      this.timer1.Start();

      this.lblMessage.Text = "距离当前关机还有" +60+ "秒";

    }
    int max = 60;
    private void timer1_Tick(object sender, EventArgs e)
    {
      this.max = max - 1;
      if (this.max == 0)
      {
        System.Diagnostics.Process.Start("cmd.exe", "/cshutdown -s -t 0");
        this.timer1.Stop();
      }
      else
      {
        this.lblMessage.Text = "距离当前关机还有" + this.max.ToString() + "秒";
      }
    }
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • c#调用api控制windows关机示例(可以重启/注销)

    方法一:调用windows自带的shutdown.exe (缺点:会出现倒计时窗口) System.Diagnostics.Process.Start("shutdown.exe", "-r -f -t 15"); shutdown参数含义:-r关闭并重启动此计算机:-f 强制运行的应用程序关闭而没有警告:-t 15 延时15shutdown.exe的详细用法: shutdown [-i | -l | -s | -r | -a] [-f] [-m //compute

  • C#关机小程序源码

    下面是运行的效果图 核心代码: 复制代码 代码如下: 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; /* * * 整理:张晓天 * Q Q:977602650 * 日期:2012

  • C#实现关机重启及注销实例代码

    本文所述的C#实例代码是一个基于Visual C#2010编写的关机.重启.注销程序,类似的C#程序网上还有不少,每个人的写法都各有不同,这段程序供新手参考下.本代码中还用到了一个计时器,用来显示系统运行的时间,以下为完整实例代码: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.D

  • C#窗口实现定时关机系统

    本文实例为大家分享了C#窗口实现定时关机系统的具体代码,供大家参考,具体内容如下 看一下运行之后的效果图 看代码 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; namespace

  • C语言编写简单的定时关机程序

    写一个定时关机的小程序,可以立即关闭计算机,也可以一段时间后关闭计算机. 这里主要考察system()命令. 代码实现: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char cmd[20]="shutdown -s -t "; char t[5]="0"; int c; system("title C语言关机程序")

  • 如何利用DOS批处理实现定时关机操作详解

    一.批处理释义: 批处理(Batch),也称为批处理脚本.它是对某对象进行批量的处理,通常被认为是一种简化的脚本语言,应用于DOS和Windows系统中.批处理文件的扩展名为bat. 目前比较常见的批处理包含两类:DOS批处理和PS批处理.PS批处理是基于强大的图片编辑软件Photoshop的,用来批量处理图片的脚本:而DOS批处理则是基于DOS命令的,用来自动地批量地执行DOS命令以实现特定操作的脚本. 二.编写批处理文件: (1)新建一个文本文件,在里面写上DOS命令语句.然后选择另存为改文

  • 可以设定的定时关机的批处理

    批处理定时关机.bat 复制代码 代码如下: @echo off mode con lines=25 title 定时关机 color 1f cls echo. echo. echo. echo. echo 时间使用24小时制(如2:15.12:00),可以输入多个时间点 echo. echo 多个时间点用空格分隔 echo. echo. echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ echo. set times= set /p times= 请输

  • vbs实现的定时关机、重启的脚本和程序

    将下面代码存为vbs文件,如:shutdown.vbs,然后双击或在文件上点右 键选择以命令提示打开,如果到了你设置重启的时候,系统会出现关机的对话 框. 直接下面代码程序会出现关机的对话框,最后的回车注释掉了,正常使用 时,请去掉注释符. 以下代码在window 2000 下通过. 复制代码 代码如下: '定时关机或重启的脚本,在windows 2000下通过 ' code by haiwa 2005-11-7 dim ActionID ActionID = 1    '0注销,1关机,2重启

  • 批处理 实现定时关机、注销、重启、锁定等功能

    复制代码 代码如下: @ECHO off TITLE greaterthanme-实现定时关机.注销.重启.锁定等功能.start CLS COLOR 1f rem 使用COLOR命令对控制台输出颜色进行更改 MODE con COLS=41 LINES=18 rem MODE语句为设定窗体的宽和高 set tm1=%time~0,2% set tm2=%time~3,2% set tm3=%time~6,2% ECHO %date% %tm1%点%tm2%分%tm3%秒 ECHO ======

  • java实现电脑定时关机的方法

    本文实例讲述了java如何注册成windows服务程序及一个简单的java定时关机程序代码,分享给大家供大家参考.具体方法如下: 一.问题: 最近想找个软件来控制电脑的关机时间,在网上找了几个,都是可视化界面的可以设置具体的关机时间的软件.由于我想编写的关机程序是运行在别人机器上,只能让该机器在晚上17 点到23 点25 分才上网,到了23 点25 分就可以自动关机.为了让别人感觉不到这个软件的"存在"(免得使用者自己关闭定时关机软件),所以我想把关机软件注册为服务的方式,运行在后台.

  • 利用Python实现Windows定时关机功能

    是最初的几个爬虫,让我认识了Python这个新朋友,虽然才刚认识了几天,但感觉有种莫名的默契感.每当在别的地方找不到思路,总能在Python找到解决的办法.自动关机,在平时下载大文件,以及跑程序的时候能用到的,刚才写了个windows自动关机的小程序,程序过于简单,就当是玩玩吧,当然还有很多可改进的地方.下面正文:  #ui制作: 照旧,笔者由Qt制作完成需要的ui,包括label,label_2,label_3,lable_4,lineEdit,lineEdit_2,pushButton组件.

  • 用python写一个windows下的定时关机脚本(推荐)

    由于本人经常使用笔记本共享WiFi,但是又不想笔记本开机一夜(为了低碳环保嘛 ~_~!),所以每次都要用使用DOS命令关机,感觉好麻烦.正好最近在学习Python,于是决定用python写一个定时关机的脚本: 话不多说由于代码比较简单,直接上代码. 代码块 # -*- coding: utf-8 -*- """ Created on Sat Dec 19 11:18:16 2015 @author: win7 """ '''定时关机''' '''

  • C#实现定时关机小应用

    C# 定时关机小应用(Winform),供大家参考,具体内容如下 一.简述 记--使用winform实现的定时关机小应用.通过执行cmd命令实现的.(Visual Studio 2010旗舰版) 例子打包:链接 二.效果 三.工程结构及布局视图 四.源文件 Form1.cs文件 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.D

随机推荐