C#桌面應(yīng)用開發(fā)實(shí)現(xiàn)番茄定時(shí)器
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)文章希望大家以后多多支持腳本之家!
- c#定時(shí)器使用示例詳解
- C#定時(shí)器實(shí)現(xiàn)自動(dòng)執(zhí)行的方法
- C#中timer定時(shí)器用法實(shí)例
- 詳解C#中的定時(shí)器Timer類及其垃圾回收機(jī)制
- c# 區(qū)分幾種定時(shí)器(timer)
- C# 創(chuàng)建高精度定時(shí)器的示例
- c#如何利用定時(shí)器自動(dòng)備份數(shù)據(jù)庫詳解
- C# Quartzs定時(shí)器的使用教程
- C#中Timer定時(shí)器類的簡單使用
- C#定時(shí)器組件FluentScheduler用法
- c# 線程定時(shí)器 System.Threading.Timer的使用
- C#中多種高效定時(shí)器方法的使用詳解
- C#中四種定時(shí)器的用法詳解
相關(guān)文章
C++實(shí)現(xiàn)LeetCode(109.將有序鏈表轉(zhuǎn)為二叉搜索樹)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(109.將有序鏈表轉(zhuǎn)為二叉搜索樹),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07詳解C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法
這篇文章主要介紹了C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法,文中代碼有一個(gè)針對各種系統(tǒng)進(jìn)行判斷來加載不同頭文件的方法,需要的朋友可以參考下2016-03-03利用C++實(shí)現(xiàn)一個(gè)線程安全的map
這篇文章主要為大家詳細(xì)介紹了如何利用C++實(shí)現(xiàn)一個(gè)線程安全的map(使用ChatCPT生成),代碼是通過兩輪對話完善的,感興趣的小伙伴可以了解一下2023-05-05概率的問題:使用遞歸與多次試驗(yàn)?zāi)M的分析
以下對概率的問題:使用了遞歸和多次試驗(yàn)?zāi)M。需要的朋友參考下2013-05-05詳解C語言中的char數(shù)據(jù)類型及其與int類型的轉(zhuǎn)換
這篇文章主要介紹了詳解C語言中的char數(shù)據(jù)類型及其與int類型的轉(zhuǎn)換,是C語言入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下2015-08-08C++算法學(xué)習(xí)之分支限界法的應(yīng)用
分支限界法常以廣度優(yōu)先或以最小耗費(fèi)(最大效益)優(yōu)先的方式搜索問題的解空間樹。本文將詳細(xì)講解分支限界法的應(yīng)用,需要的可以參考一下2022-05-05