亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#桌面應用開發(fā)實現(xiàn)番茄定時器

 更新時間:2024年07月10日 09:20:49   作者:Leapahead1949  
本文主要介紹了C#桌面應用開發(fā)實現(xiàn)番茄定時器,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1、環(huán)境搭建和工程創(chuàng)建:

步驟一:安裝visual studio2022

步驟二:新建工程

在這里插入圖片描述

2、制作窗體部件

*踩過的坑:

(1)找不到工具箱控件,現(xiàn)象如下:

在這里插入圖片描述

解決辦法:

依次點擊:工具欄->獲取工具和功能->單個組件:安裝3.5版本開發(fā)工具

在這里插入圖片描述

若上述

在這里插入圖片描述

辦法不生效,繼續(xù)檢查.NET桌面開發(fā)和ASP.NET開發(fā)是否勾選

最后點擊頂部欄的:視圖->工具箱就能顯示出工具欄

3、界面布局設計

(1)界面設計如下:

在這里插入圖片描述

4、具體功能函數(shù)

using System;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace MyProject01
{
    public partial class Form1 : Form
    {
        UInt16 Timer_Value = 0; //定時值
        UInt16 Timer_Count = 0; //定時器計數(shù)值
        byte Timer_Status = 0;  //定時器狀態(tài) 0--停止  1 -- 定時狀態(tài)  2 --暫停狀態(tài)




        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            byte i;

            for (i = 0; i < 60; i++)
            {
                //分鐘和秒鐘的組合框初始化
                comboBox1.Items.Add(i.ToString());
                comboBox2.Items.Add(i.ToString());

                comboBox1.Text = "45";  //初始化為45分鐘
                comboBox2.Text = "0";


            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            textBox1.ReadOnly = true;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            //定時器狀態(tài)機函數(shù)
            switch (Timer_Status)
            {
                case 0:
                    {
                        //獲取定時時間,分鐘*60+秒鐘
                        Timer_Value = Convert.ToUInt16(comboBox1.Text, 10);
                        Timer_Value *= 60;
                        Timer_Value += Convert.ToUInt16(comboBox2.Text, 10);

                        if (Timer_Value > 0)
                        {

                            //開始定時任務
                            textBox1.Text = Timer_Value.ToString() + " 秒";
                            button1.Text = "暫停計時";
                            button2.Enabled = true;

                            comboBox1.Enabled = false;  //關閉時間選擇
                            comboBox2 .Enabled = false;

                            timer1.Start();

                            Timer_Status = 1;

                        }
                        else
                        {

                            MessageBox.Show("定時時間不能為0,請重新輸入", "警告");
                            //
                        }

                        //進度條初始化
                        progressBar1.Value = 0;
                        progressBar1.Maximum = Timer_Value;

                        break;
                    }
                case 1:
                    {
                        timer1.Stop();
                        Timer_Status = 2;
                        button1.Text = "繼續(xù)計時";
                        break;
                    }
                case 2:
                    {
                        timer1.Start();
                        Timer_Status = 1;
                        button1.Text = "暫停計時";
                        break;
                    }
                default:
                    {

                        break;
                    }


            }
        }

        //定時按鈕單擊事件
        private void timer1_Tick(object sender, EventArgs e)
        {


            Timer_Count++;
            textBox1.Text = Timer_Value-Timer_Count + " 秒";

            //更新進度條
            progressBar1.Value = Timer_Count;


            if (Timer_Count == Timer_Value)
            {
                timer1.Stop();
                Timer_Count = 0;
                System.Media.SystemSounds.Asterisk.Play();

                button1.Text = "計時結束";
                
                MessageBox.Show ("定時時間到","提示");
                button1.Text = "開始定時";

                comboBox1.Enabled = true;  //關閉時間選擇
                comboBox2.Enabled = true;


                comboBox1.Text = "45";  //初始化為45分鐘
                comboBox2.Text = "0";

                button2.Enabled = false;

                Timer_Status = 0;
                progressBar1.Value = 0;


                
            }

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {

            if(Timer_Status > 0)
            {
                Timer_Value = 0; //定時值
                Timer_Count = 0;
                Timer_Status = 0;
                progressBar1.Value = 0;
                textBox1.Text= "0";
            }



            timer1.Stop();
            Timer_Count = 0;

            button1.Text = "開始定時";

            comboBox1.Enabled = true;  //關閉時間選擇
            comboBox2.Enabled = true;


            comboBox1.Text = "45";  //初始化為45分鐘
            comboBox2.Text = "0";

            button2.Enabled = false;

            Timer_Status = 0;
            Timer_Value = 0;
        }
    }
}

到此這篇關于C#桌面應用開發(fā)實現(xiàn)番茄定時器的文章就介紹到這了,更多相關C# 番茄定時器內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家! 

相關文章

最新評論