首先一个程序第一要素是logo

在设置里面可以设置程序图标,在ICON里设置。

ICON图标可以在网上下载。

这些都是表面功夫

程序中涉及到Buton、Label、Timer、Notiflcon控件

Button按钮控件,可以设计点击事件

如下所示:

private void button1_Click(object sender, EventArgs e)
{
// int shi, fen, miao;
if (Flag_True == 0)
{
Flag_True = 1;
}
else
{
button1.Text = "确定";
label6.Text = " ";
label7.Text = " ";
label5.Text = " ";
//label1.Text = "定时关机设置";
Flag_True = 0;
}
shi = (int)numericUpDown3.Value;
fen = (int)numericUpDown2.Value;
miao = (int)numericUpDown1.Value;
time_set = shi * 3600 + fen * 60 + miao;
}

label控件操作简单

能够显示字符,并且其成员有text,可以随时更改文本

timer控件相当于嵌入式中的定时器,在属性中行为一栏中设置ENABLE 并且设置interval时间间隔500就是半秒。

private void timer1_Tick(object sender, EventArgs e)
{
Int32 time_now;
Int32 extra;
if (Flag_True == 1)
{
if (DateTime.Now.Minute == fen && DateTime.Now.Hour == shi && DateTime.Now.Second == miao)
{
button1.Text = "取消";
label6.Text = "剩余关机时间";
label7.Text = "秒";
label5.Text = "0";
System.Diagnostics.Process.Start("shutdown","-s -t 0");//关机程序
}//shutdown
else
{
time_now = DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 3600;
extra = time_set - time_now;
if (extra > 0)
{
button1.Text = "取消";
label6.Text = "剩余关机时间";
label7.Text = "秒";
//extra/3600
label5.Text = extra.ToString();
}
else
{
Flag_True = 0;
} }
}
}

上面我每隔半秒进入中断一次,判断,如果已经设置过定时关机,就判断是否到达关机时间,并显示还剩多少秒关机。如果没有设置定时关机,就不显示。

其中button1和Label的text都可以随时更改。

基本功能设置完成

接下来还有一个最小化到托盘的设置

用到Notiflcon控件

此控件设置最小化图标,在设置里可以设置icon图标。

他带有的事件有鼠标单击,鼠标双击,单击,双击。

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

上述我设置了鼠标单击,代码里是恢复可视化,正常窗口。

再之得设置程序最小化时隐藏在下边

private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon1.Visible = true;
}
}

上述就是一个关机程序,自己做着玩的。。

整体构架如下图所示。

namespace 关机任务管理V1._0
{
public partial class Form1 : Form
{
int shi, fen, miao;
Int32 time_set;
int Flag_True = 0;
public Form1()
{ InitializeComponent(); } private void Form1_Load(object sender, EventArgs e)
{ } private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown1.Value == -1)
numericUpDown1.Value = 60;
else if (numericUpDown1.Value == 61)
numericUpDown1.Value = 0;
} private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown2.Value == -1)
numericUpDown2.Value = 60;
else if (numericUpDown2.Value == 61)
numericUpDown2.Value = 0; } private void numericUpDown3_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown3.Value == 25)
numericUpDown3.Value = 0;
else if (numericUpDown3.Value == -1)
numericUpDown3.Value = 24;
} private void button1_Click(object sender, EventArgs e)
{
// int shi, fen, miao;
if (Flag_True == 0)
{
Flag_True = 1;
}
else
{
button1.Text = "确定";
label6.Text = " ";
label7.Text = " ";
label5.Text = " ";
//label1.Text = "定时关机设置";
Flag_True = 0;
}
shi = (int)numericUpDown3.Value;
fen = (int)numericUpDown2.Value;
miao = (int)numericUpDown1.Value;
time_set = shi * 3600 + fen * 60 + miao;
} private void timer1_Tick(object sender, EventArgs e)
{
Int32 time_now;
Int32 extra;
if (Flag_True == 1)
{
if (DateTime.Now.Minute == fen && DateTime.Now.Hour == shi && DateTime.Now.Second == miao)
{
button1.Text = "取消";
label6.Text = "剩余关机时间";
label7.Text = "秒";
label5.Text = "0";
System.Diagnostics.Process.Start("shutdown","-s -t 0");//关机程序
}//shutdown
else
{
time_now = DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 3600;
extra = time_set - time_now;
if (extra > 0)
{
button1.Text = "取消";
label6.Text = "剩余关机时间";
label7.Text = "秒";
//extra/3600
label5.Text = extra.ToString();
}
else
{
Flag_True = 0;
} }
}
} private void label5_Click(object sender, EventArgs e)
{ } private void label4_Click(object sender, EventArgs e)
{ } private void label3_Click(object sender, EventArgs e)
{ } private void label6_Click(object sender, EventArgs e)
{ } private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
this.notifyIcon1.Visible = false;
}
//最小化代码
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.notifyIcon1.Visible = true;
}
}
}
}

界面如下:

C#编写自动关机程序复习的知识的更多相关文章

  1. 32位汇编第二讲,编写窗口程序,加载资源,响应消息,以及调用C库函数

    32位汇编第二讲,编写窗口程序,加载资源,响应消息,以及调用C库函数 (如果想看所有代码,请下载课堂资料,里面有所有代码,这里会讲解怎么生成一个窗口程序) 一丶32位汇编编写Windows窗口程序 首 ...

  2. 如何让VS2012编写的程序在XP下运行

    Win32主程序需要以下设置 第一步:在工程属性General设置 第二步:在C/C++ Code Generation 设置 第三步:SubSystem 和  Minimum Required Ve ...

  3. C#入门到精通系列课程——第2章编写C#程序

    ◆本章内容 (1)熟悉Visual Studio 2017开发环境 (2)编写第一个C#程序 (3)C#程序结构预览 (4)程序编写规范 (5)难点解答 ◆本章简述 要学习C#编程,必然要熟悉C#程序 ...

  4. Java初学者作业——编写JAVA程序,根据用户输入课程名称,输出对应课程的简介,各门课程的简介见表

    返回本章节 返回作业目录 需求说明: 编写JAVA程序,根据用户输入课程名称,输出对应课程的简介,各门课程的简介见表 课程名称 课程简介 JAVA课程 JAVA语言是目前最流行的编写语言,在本课程中将 ...

  5. CSharpGL(11)用C#直接编写GLSL程序

    CSharpGL(11)用C#直接编写GLSL程序 +BIT祝威+悄悄在此留下版了个权的信息说: 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharp ...

  6. 在Linux上编写C#程序

    自从C#开源之后,在Linux编写C#程序就成了可能.Mono-project就是开源版本的C#维护项目.在Linux平台上使用的C#开发工具为monodevelop.安装方式如下: 首先需要安装一些 ...

  7. 35.按要求编写Java程序: (1)编写一个接口:InterfaceA,只含有一个方法int method(int n); (2)编写一个类:ClassA来实现接口InterfaceA,实现int method(int n)接口方 法时,要求计算1到n的和; (3)编写另一个类:ClassB来实现接口InterfaceA,实现int method(int n)接口 方法时,要求计算n的阶乘(n

      35.按要求编写Java程序: (1)编写一个接口:InterfaceA,只含有一个方法int method(int n): (2)编写一个类:ClassA来实现接口InterfaceA,实现in ...

  8. 如何让VS2013编写的程序

    总体分c++程序和c#程序 1.c++程序 这个用C++编写的程序可以经过设置后在XP下运行,主要的“平台工具集”里修改就可以. 额外说明:(1)程序必须为Dotnet 4.0及以下版本.(XP只支持 ...

  9. 编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

    编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值 1 #import <Foundation/Foundation.h>  2   3 int main( ...

随机推荐

  1. ABAP(笔记)

    1.excel表格上传 *&---------------------------------------------------------------------* ** 程序名称:ZSD ...

  2. iOS 应用性能测试的相关方法、工具及技巧

    用户不喜欢等待.他们不关心也不应该关心一个应用初始化的时候需要什么,他们只想尽快地完成他们的任务.你的应用应该几乎是瞬间启动的,其界面应当如丝般顺滑.在充满竞争的软件市场中,应用的性能是关键的优势之一 ...

  3. 【Android】随时随地退出程序

    新建一个 ActivityCollector 类作为活动管理器,代码如下所示:public class ActivityCollector {public static List<Activit ...

  4. System Operations on AWS - Lab 7 - CloudFormation

    CloudFormation模板:创建一个VPC(包含Public子网,Private子网,分别在不同的AZ),创建NAT,Bastion Server在Public子网. 1. 修改并运行AWS C ...

  5. Go语言学习资料汇总

    网站: Go语言官网(访问)(中文镜像) Go语言中文网(访问) Go编译器(访问) Go语言中国社区(访问) golanghome(访问) GoLang中国(访问) Gopher Academic( ...

  6. springmvc使用aop心得

    第一步:创建aop拦截类: @Component @Aspect public class ControllerSelectorInterceptor { @Before("executio ...

  7. Spring声明式事务(xml配置事务方式)

    Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...

  8. js--小结③

  9. ASP.NET MVC——Controller的激活

    Controller的激活是根据在路由过程得到的Controller名称来创建对应的Controller对象.相关类如图: Controller激活的过程可通过如下序列图表示: 代码示例如下: str ...

  10. javascript-设置div隐藏

    html code: <div class="title"> <ul id="col02_left_title"> <li> ...