当前位置: 首页 > news >正文

C#桌面应用开发:番茄定时器

C#桌面应用开发:番茄定时器

1、环境搭建和工程创建:

步骤一:安装visual studio2022

步骤二:新建工程
在这里插入图片描述

2、制作窗体部件

*踩过的坑:

(1)找不到工具箱控件,现象如下:

在这里插入图片描述

解决办法:

依次点击:工具栏->获取工具和功能->单个组件:安装3.5版本开发工具
在这里插入图片描述

若上述在这里插入图片描述
办法不生效,继续检查.NET桌面开发和ASP.NET开发是否勾选

最后点击顶部栏的:视图->工具箱就能显示出工具栏

3、界面布局设计

(1)界面设计如下:

在这里插入图片描述

4、具体功能函数

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; //定时器计数值byte Timer_Status = 0;  //定时器状态 0--停止  1 -- 定时状态  2 --暂停状态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){//定时器状态机函数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 = "继续计时";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;}}
}
http://www.lryc.cn/news/392004.html

相关文章:

  • PHP智慧门店微信小程序系统源码
  • SerDes介绍以及原语使用介绍(2)OSERDESE2原语仿真
  • 【稳定检索/投稿优惠】2024年教育、人文发展与艺术国际会议(EHDA 2024)
  • Docker拉取失败,利用 Git将 Docker镜像重新打 Tag 推送到阿里云等其他公有云镜像仓库里
  • 【区分vue2和vue3下的element UI Breadcrumb 面包屑组件,分别详细介绍属性,事件,方法如何使用,并举例】
  • gdb调试命令大全
  • ESP32之arduino环境安装及点灯
  • 查看VUE中安装包依赖的版本号
  • 博途通讯笔记1:1200与1200之间S7通讯
  • Kafka搭建(集群版)
  • 【康复学习--LeetCode每日一题】3115. 质数的最大距离
  • 【yolov8系列】ubuntu上yolov8的开启训练的简单记录
  • Scala学习笔记15: 文件和正则表达式
  • 外卖员面试现状
  • 异步加载与动态加载
  • MUNIK解读ISO26262--什么是DFA
  • 启动spring boot项目停止 提示80端口已经被占用
  • SOLIDWORKS分期许可(订阅形式),降低前期的投入成本!
  • 详细分析Spring Boot 数据源配置的基本知识(附配置)
  • 海思SD3403/SS928V100开发(15)9轴IMU ICM-20948模块SPI接口调试
  • 大力出奇迹:大语言模型的崛起与挑战
  • 【算法 - 哈希表】两数之和
  • 【深度学习】图形模型基础(5):线性回归模型第一部分:认识线性回归模型
  • 2024 年第十四届 APMCM 亚太地区大学生数学建模竞赛B题超详细解题思路+数据预处理问题一代码分享
  • Yarn有哪些功能特点
  • 深度学习算法bert
  • PyTorch - 神经网络基础
  • docker-compose搭建minio对象存储服务器
  • vue3使用pinia中的actions,需要调用接口的话
  • Python酷库之旅-第三方库Pandas(003)