C # Writing automatic shutdown Program Review knowledge

Source: Internet
Author: User

First, the first element of a program is the logo

In the settings you can set the program icon, in the icon set.

Icon icons can be downloaded online.

These are all superficial kung fu

The program involves Buton, Label, Timer, Notiflcon control

Button control to design a click event

As shown below:

private void Button1_Click (object sender, EventArgs e)        {           //int shi, fen, Miao;            if (flag_true = = 0)            {                flag_true = 1;            }            else            {                button1. Text = "OK";                Label6. Text = "";                Label7. Text = "";                Label5. Text = "";                Label1. Text = "Timer shutdown settings";                flag_true = 0;            }            Shi = (int) numericupdown3.value;            Fen = (int) numericupdown2.value;            Miao = (int) numericupdown1.value;            Time_set = shi * 3600 + fen * + miao;        }

Label control is simple to operate

Ability to display characters, and its members have text, you can change the text at any time

The timer control is equivalent to the timer in the embedded, set enable in the behavior column of the attribute and set interval time interval 500 is half a second.

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 &&A mp DateTime.Now.Second = = Miao) {button1.                    Text = "Cancel"; Label6.                    Text = "Remaining shutdown time"; Label7.                    Text = "seconds"; Label5.                    Text = "0";                System.Diagnostics.Process.Start ("Shutdown", "-s-t 0");//Shutdown Program}//shutdown Else                    {Time_now = DateTime.Now.Second + DateTime.Now.Minute * + DateTime.Now.Hour * 3600;                    Extra = Time_set-time_now; if (Extra > 0) {button1.                        Text = "Cancel"; Label6.                        Text = "Remaining shutdown time"; Label7.                        Text = "seconds";                     extra/3600   Label5. Text = extra.                    ToString ();                    } else {flag_true = 0; }                                                            }            }        }

I go to interrupt every half second, judge, if you have set a timed shutdown, determine whether to reach the shutdown time, and show how many seconds left off. If you do not set a timed shutdown, it is not displayed.

The text of Button1 and label can be changed at any time.

Basic function Setup Complete

And then there's a setup to minimize to the pallet

Use the Notiflcon control

This control sets the minimize icon, which can be set in the icon.

He has an event with a mouse click, double click on the mouse, and double-clicked.

private void Notifyicon1_mouseclick (object sender, MouseEventArgs e)        {this            . Visible = true;             This. WindowState = Formwindowstate.normal;             This.notifyIcon1.Visible = false;         }

The above I set the mouse click, the code is to restore the visual, Normal window.

Again, the Setup program is minimized and hidden below.

private void Form1_sizechanged (object sender, EventArgs e)        {            if (this. WindowState = = formwindowstate.minimized)             {this                 . Hide ();                 This.notifyIcon1.Visible = true;             }         }

The above is a shutdown program, do their own play.

The overall architecture is as shown.

Namespace shutdown task management 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 Numericupdo Wn1_valuechanged (object sender, EventArgs e) {if (Numericupdown1.value = =-1) numericupd Own1.            Value = 60;        else if (Numericupdown1.value = =) Numericupdown1.value = 0;  private void Numericupdown2_valuechanged (object sender, EventArgs e) {if (numericupdown2.value            = =-1) numericupdown2.value = 60;                else if (Numericupdown2.value = =) 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 = "OK"; Label6.                Text = ""; Label7.                Text = ""; Label5.                Text = ""; Label1.                Text = "Timer shutdown settings";            flag_true = 0;            } shi = (int) numericupdown3.value;            Fen = (int) numericupdown2.value;            Miao = (int) numericupdown1.value;        Time_set = shi * 3600 + fen * + 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 = "Cancel"; Label6.                    Text = "Remaining shutdown time"; Label7.                    Text = "seconds"; Label5.                    Text = "0";                System.Diagnostics.Process.Start ("Shutdown", "-s-t 0");//Shutdown Program}//shutdown Else                    {Time_now = DateTime.Now.Second + DateTime.Now.Minute * + DateTime.Now.Hour * 3600;                    Extra = Time_set-time_now; if (Extra > 0) {button1.                        Text = "Cancel"; Label6.                        Text = "Remaining shutdown time"; Label7.                        Text = "seconds"; extra/3600 Label5. Text = extra.                    ToString ();                    } else {flag_true = 0;         }                                                            }   }} private void Label5_click (object sender, EventArgs e) {} private void Label4_cl        Ick (object sender, EventArgs e) {} private void Label3_click (object sender, EventArgs e) { private void Label6_click (object sender, EventArgs e) {} private void notifyicon1_mous Eclick (object sender, MouseEventArgs e) {this.             Visible = true; This.             WindowState = Formwindowstate.normal;         This.notifyIcon1.Visible = false; }//Minimize code private void Form1_sizechanged (object sender, EventArgs e) {if (this. WindowState = = formwindowstate.minimized) {this.                 Hide ();             This.notifyIcon1.Visible = true; }         }    }}

The interface is as follows:

C # Writing automatic shutdown Program Review knowledge

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.