Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write automatic shutdown Program in C #

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to write an automatic shutdown program in C#", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "how to write an automatic shutdown program in C#".

First of all, the element of a program is logo.

You can set the program icon in the settings and set it in ICON.

The ICON icon can be downloaded online.

These are all superficial skills.

Buton, Label, Timer and Notiflcon controls are involved in the program.

Button button control, you can design click events

As follows:

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

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 = "timing shutdown setting"

Flag_True = 0

}

Shi = (int) numericUpDown3.Value

Fen = (int) numericUpDown2.Value

Miao = (int) numericUpDown1.Value

Time_set = shi * 3600 + fen * 60 + miao

}

Label control is easy to operate.

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

The timer control is equivalent to an embedded timer, setting ENABLE in the row column of the property and setting the interval interval of 500is half a second.

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

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 * 60 + 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

}

}

}

}

Above, I enter the interrupt every half a second to judge whether the shutdown time has been reached if the scheduled shutdown has been set, and show how many seconds of shutdown are left. If the timing shutdown is not set, it will not be displayed.

The text of both button1 and Label can be changed at any time.

Basic function setup completed

Then there is a setting that is minimized to the tray.

Use the Notiflcon control

This control sets the minimization icon, where you can set the icon icon.

He comes with events such as mouse clicks, double clicks, clicks, double clicks.

one

two

three

four

five

six

Private void notifyIcon1_MouseClick (object sender, MouseEventArgs e)

{

This.Visible = true

This.WindowState = FormWindowState.Normal

This.notifyIcon1.Visible = false

}

Above I set up the mouse click, the code is to restore visualization, the normal window.

Then, when the program is minimized, it can be hidden below.

one

two

three

four

five

six

seven

eight

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 fun.

The overall architecture is shown in the following figure.

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

thirty-six

thirty-seven

thirty-eight

thirty-nine

forty

forty-one

forty-two

forty-three

forty-four

forty-five

forty-six

forty-seven

forty-eight

forty-nine

fifty

fifty-one

fifty-two

fifty-three

fifty-four

fifty-five

fifty-six

fifty-seven

fifty-eight

fifty-nine

sixty

sixty-one

sixty-two

sixty-three

sixty-four

sixty-five

sixty-six

sixty-seven

sixty-eight

sixty-nine

seventy

seventy-one

seventy-two

seventy-three

seventy-four

seventy-five

seventy-six

seventy-seven

seventy-eight

seventy-nine

eighty

eighty-one

eighty-two

eighty-three

eighty-four

eighty-five

eighty-six

eighty-seven

eighty-eight

eighty-nine

ninety

ninety-one

ninety-two

ninety-three

ninety-four

ninety-five

ninety-six

ninety-seven

ninety-eight

ninety-nine

one hundred

one hundred and one

one hundred and two

one hundred and three

one hundred and four

one hundred and five

one hundred and six

one hundred and seven

one hundred and eight

one hundred and nine

one hundred and ten

one hundred and eleven

one hundred and twelve

one hundred and thirteen

one hundred and fourteen

one hundred and fifteen

one hundred and sixteen

one hundred and seventeen

one hundred and eighteen

one hundred and nineteen

one hundred and twenty

one hundred and twenty one

one hundred and twenty two

one hundred and twenty three

one hundred and twenty four

one hundred and twenty five

one hundred and twenty six

one hundred and twenty seven

one hundred and twenty eight

one hundred and twenty nine

one hundred and thirty

one hundred and thirty one

one hundred and thirty two

one hundred and thirty three

one hundred and thirty four

one hundred and thirty five

one hundred and thirty six

one hundred and thirty seven

one hundred and thirty eight

one hundred and thirty nine

Namespace shutdown task management V1.room0

{

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 = "OK"

Label6.Text = ""

Label7.Text = ""

Label5.Text = ""

/ / label1.Text = "timing shutdown setting"

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 = "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 * 60 + 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_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

}

/ / minimize the 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:

The above is all the contents of the article "how to write an automatic shutdown program in C#". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report