亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#如何編寫自動關機程序

發布時間:2021-12-03 10:31:27 來源:億速云 閱讀:372 作者:小新 欄目:編程語言

這篇文章主要為大家展示了“C#如何編寫自動關機程序”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“C#如何編寫自動關機程序”這篇文章吧。

C#如何編寫自動關機程序

首先一個程序***要素是logo

在設置里面可以設置程序圖標,在ICON里設置。

ICON圖標可以在網上下載。

這些都是表面功夫

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

Button按鈕控件,可以設計點擊事件

如下所示:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

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就是半秒。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

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圖標。

他帶有的事件有鼠標單擊,鼠標雙擊,單擊,雙擊。

1

2

3

4

5

6

private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)

        {

            this.Visible = true;

            this.WindowState = FormWindowState.Normal;

            this.notifyIcon1.Visible = false;

        }

上述我設置了鼠標單擊,代碼里是恢復可視化,正常窗口。

再之得設置程序最小化時隱藏在下邊

1

2

3

4

5

6

7

8

private void Form1_SizeChanged(object sender, EventArgs e)

        {

            if (this.WindowState == FormWindowState.Minimized)

            {

                this.Hide();

                this.notifyIcon1.Visible = true;

            }

        }

上述就是一個關機程序,自己做著玩的。。

整體構架如下圖所示。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

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#如何編寫自動關機程序

以上是“C#如何編寫自動關機程序”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

天津市| 得荣县| 法库县| 平远县| 陇南市| 乐山市| 茌平县| 和龙市| 紫云| 湘潭县| 潜山县| 军事| 章丘市| 额尔古纳市| 昌邑市| 松溪县| 岚皋县| 冀州市| 平阴县| 合山市| 温泉县| 镶黄旗| 寿光市| 十堰市| 江川县| 黎城县| 浦江县| 鞍山市| 类乌齐县| 蒲城县| 上林县| 淮阳县| 清镇市| 保靖县| 闽清县| 资讯| 城市| 赫章县| 恩平市| 延庆县| 古蔺县|