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ù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
C++實現(xiàn)LeetCode(109.將有序鏈表轉為二叉搜索樹)
這篇文章主要介紹了C++實現(xiàn)LeetCode(109.將有序鏈表轉為二叉搜索樹),本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下2021-07-07詳解C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法
這篇文章主要介紹了C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法,文中代碼有一個針對各種系統(tǒng)進行判斷來加載不同頭文件的方法,需要的朋友可以參考下2016-03-03詳解C語言中的char數(shù)據(jù)類型及其與int類型的轉換
這篇文章主要介紹了詳解C語言中的char數(shù)據(jù)類型及其與int類型的轉換,是C語言入門學習中的基礎知識,需要的朋友可以參考下2015-08-08