欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

步驟一:安裝visual studio2022

步驟二:新建工程

在這里插入圖片描述

2、制作窗體部件

*踩過的坑:

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

在這里插入圖片描述

解決辦法:

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

在這里插入圖片描述

若上述

在這里插入圖片描述

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

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

3、界面布局設(shè)計(jì)

(1)界面設(shè)計(jì)如下:

在這里插入圖片描述

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; //定時(shí)值
        UInt16 Timer_Count = 0; //定時(shí)器計(jì)數(shù)值
        byte Timer_Status = 0;  //定時(shí)器狀態(tài) 0--停止  1 -- 定時(shí)狀態(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)
        {
            //定時(shí)器狀態(tài)機(jī)函數(shù)
            switch (Timer_Status)
            {
                case 0:
                    {
                        //獲取定時(shí)時(shí)間,分鐘*60+秒鐘
                        Timer_Value = Convert.ToUInt16(comboBox1.Text, 10);
                        Timer_Value *= 60;
                        Timer_Value += Convert.ToUInt16(comboBox2.Text, 10);

                        if (Timer_Value > 0)
                        {

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

                            comboBox1.Enabled = false;  //關(guān)閉時(shí)間選擇
                            comboBox2 .Enabled = false;

                            timer1.Start();

                            Timer_Status = 1;

                        }
                        else
                        {

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

                        //進(jìn)度條初始化
                        progressBar1.Value = 0;
                        progressBar1.Maximum = Timer_Value;

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

                        break;
                    }


            }
        }

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


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

            //更新進(jìn)度條
            progressBar1.Value = Timer_Count;


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

                button1.Text = "計(jì)時(shí)結(jié)束";
                
                MessageBox.Show ("定時(shí)時(shí)間到","提示");
                button1.Text = "開始定時(shí)";

                comboBox1.Enabled = true;  //關(guān)閉時(shí)間選擇
                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; //定時(shí)值
                Timer_Count = 0;
                Timer_Status = 0;
                progressBar1.Value = 0;
                textBox1.Text= "0";
            }



            timer1.Stop();
            Timer_Count = 0;

            button1.Text = "開始定時(shí)";

            comboBox1.Enabled = true;  //關(guān)閉時(shí)間選擇
            comboBox2.Enabled = true;


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

            button2.Enabled = false;

            Timer_Status = 0;
            Timer_Value = 0;
        }
    }
}

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

相關(guān)文章

最新評論