winfrom5 定时器namespace AlarmClock{public partial class Main : Form{// 定时器刚启动时的秒数private int secondStart 0;public Main(){InitializeComponent();}//定时器事件private void timer1_Tick(object sender, EventArgs e){// 需求每间隔1秒钟判断是否已经到休息时间如果已经到休息时间// 需要打开新窗体提醒休息一会。int minute (int)numericUpDown1.Value;int second minute * 60;secondStart;if (secondStart second) // 休息时间到{// 到达休息时间时把定时器停止。timer1_Tick事件不再执行。button2_Click(sender, e);// 隐藏Main窗体Hide();// 拿到Tip窗体的实例参数1工作分钟数参数2Main窗体Tip tipWindow new Tip(minute, this);// 打开窗体tipWindow.ShowDialog();}}//启动闹钟public void button1_Click(object sender, EventArgs e){secondStart 0; // 每次启动闹钟时把走过的秒数重置。button2.Enabled true; // 停止闹钟按钮能用timer1.Enabled true; // 让定时器能用。timer1.Start(); // 定时器启动前提定时必须能用Enabledtrue;button1.Enabled false;}//停止闹钟private void button2_Click(object sender, EventArgs e){button1.Enabled true;timer1.Stop(); // 定时器停止前提定时必须能用Enabledtrue;button2.Enabled false;}}}using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Media;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace AlarmClock{public partial class Tip : Form{// 10秒后关闭此窗体int secondClose 10;// 工作的的分钟数int minute 0;// 音频的路径static string path Application.StartupPath /alarm.wav;// 播放器SoundPlayer sp new SoundPlayer(path);// 存储一下Main窗体Main? mainForm null;public Tip(int min, Main main){InitializeComponent();minute min; // 把Main窗体中的工作分钟数存储起来将来在其他事件中使用。mainForm main; // 把Main窗体存储起来将来在其他事件中使用。}//tip定时器事件private void timer1_Tick(object sender, EventArgs e){secondClose--;label2.Text ${secondClose}秒后自动关闭;if (secondClose 0){timer1.Stop(); // 定时器停止sp.Stop(); // 音频停止Close(); // Tip窗口关闭// 把Main窗体再显示出来// mainForm?.Show();if (mainForm ! null){mainForm.Show();}}}//TIP窗体加载时private void Tip_Load(object sender, EventArgs e){label1.Text $您已经工作{minute}分钟了休息一会;label2.Text ${secondClose}秒后自动关闭;timer1.Start();// 播放音频sp.Play();}}}MVC案例 登录注册-mvc版本MODEL1.AccontInfo.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApp_mvc.Model{internal class AccontInfo{//账号public string Accont { get ; set ;}//密码public string Password { get ; set ;}//获取本地所有账号信息public static ListAccontInfo GetAccontInfo(string filePath){return JsonManage.JsonDeserializeListAccontInfo(FlieManage.ReadFile(filePath)) as ListAccontInfo;}//存储账号信息public static void SaveAccontInfo(string account,string password){///获取本地所有账号信息ListAccontInfo list GetAccontInfo(FliePathManage.UserInfoFilePath);if (list null){ //创建一个账号信息列表list new ListAccontInfo();}else{//添加账号信息list.Add(new AccontInfo(){Accont account,Password password});// 写入文件FlieManage.WriteFile(FliePathManage.UserInfoFilePath, JsonManage.JsonSerialize(list));}}}}2.FliePathManage.csusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApp_mvc{internal static class FliePathManage{// 用户信息文件路径public static string UserInfoFilePath UserInfo.txt;}}3.JsonManageusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using LitJson;namespace WindowsFormsApp_mvc.Model{internal class JsonManage{// Json 序列化public static string JsonSerialize(object obj){string jsonStr;try{jsonStr JsonMapper.ToJson(obj);}catch (Exception e){Console.WriteLine(Json 序列化: e.Message);return null;}return jsonStr;}// Json 反序列化public static object JsonDeserializeT(string json){object jsonObj;try{jsonObj JsonMapper.ToObjectT(json);}catch (Exception e){Console.WriteLine(e.Message);return null;}return jsonObj;}}}4.FlieManage.csusing System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;namespace WindowsFormsApp_mvc.Model{internal class FlieManage{//读取文件public static string ReadFile(string filePath){string content ;try{System.IO.StreamReader sr new System.IO.StreamReader(filePath);content sr.ReadToEnd();sr.Close();}catch (Exception ex){Console.WriteLine(ex.Message);return null;}return content;}//写入文件public static bool WriteFile(string filePath, string content){try{File.WriteAllText(filePath, content);}catch (Exception ex){Console.WriteLine(写入文件ex.Message);return false;}return true;}}}VIew-LoginFormusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using WindowsFormsAppLessonDay7.Model;using System.IO;namespace WindowsFormsAppLessonDay7{public partial class Form1 : Form{// 两个控件 用于在control中使用public TextBox AccontTextBox textBox1;public TextBox PasswordTextBox textBox2;// 登录成功事件 用于绑定control中方法public event Action LoginSuccessEvent;public Form1(){InitializeComponent();}// 登录按钮点击事件private void button1_Click(object sender, EventArgs e){if (LoginSuccessEvent ! null){LoginSuccessEvent();}}// 登录成功后显示消息public void ShowLoginDialog(string mes){MessageBox.Show(mes);}}}Control-LoginControlusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using WindowsFormsApp_mvc.Control;using WindowsFormsApp_mvc.View;namespace WindowsFormsApp_mvc{public partial class LoginForm : Form{public event Actionstring,string LoginEvent;public LoginForm(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){if (LoginEvent ! null){LoginEvent(textBox1.Text,textBox2.Text);}}// 登录状态显示public void LoginState(string state){MessageBox.Show(state);}private void button2_Click(object sender, EventArgs e){RegisteForm form new RegisteForm();RegisteContorl registeContorl new RegisteContorl(form);form.ShowDialog();}}}View -RegisteFormusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApp_mvc.View{public partial class RegisteForm : Form{// 注册事件public event Actionstring,string registeEvent;public RegisteForm(){InitializeComponent();}// 注册按钮点击事件private void button1_Click(object sender, EventArgs e){if (registeEvent ! null){registeEvent(textBox1.Text,textBox2.Text);}}}}Contorl-RegisteContorlusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using WindowsFormsApp_mvc.Model;using WindowsFormsApp_mvc.View;namespace WindowsFormsApp_mvc.Control{internal class RegisteContorl{//构造函数public RegisteContorl(RegisteForm form){form.registeEvent Registe;}//注册逻辑public void Registe(string account, string password){Console.WriteLine(注册逻辑执行);//保存用户信息AccontInfo.SaveAccontInfo(account, password);}}}入口类using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;using WindowsFormsApp_mvc.Control;namespace WindowsFormsApp_mvc{internal static class Program{/// summary/// 应用程序的主入口点。/// /summary[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);//登录界面LoginForm loginForm new LoginForm();//登录控制LoginControl loginControl new LoginControl(loginForm);//启动登录界面Application.Run(loginForm);}}}SunnyUI文档预览 - Gitee.com1.通过 NuGet导入SunnyUI框架2. 添加SunnyUI 控件 到工具3.使用sunnyUI-Demo 学习基本控件的使用方式使用sunnyUI-Demo 源码可以再源码中选中自己喜欢的控件比起工具箱更加的直观选择好控件我们选择复制到我们自己的项目中即可。比如 文字滚动条 复制到自己的项目中 对内容进行修改即可

相关新闻

最新新闻

Scanner内置编辑器完全教程:批量裁剪旋转、Windows Ink手写标注与PDF页面重排一次搞定

Scanner内置编辑器完全教程:批量裁剪旋转、Windows Ink手写标注与PDF页面重排一次搞定

Scanner内置编辑器完全教程:批量裁剪旋转、Windows Ink手写标注与PDF页面重排一次搞定 【免费下载链接】scanner An all-in-one scanner app for Windows 项目地址: https://gitcode.com/gh_mirrors/scanner/scanner Scanner 是一款面向 Windows 的一体化扫描…

2026/8/22 15:29:49
KMS_VL_ALL_AIO 免费上手指南:5分钟本地激活 Windows 11 与 Office

KMS_VL_ALL_AIO 免费上手指南:5分钟本地激活 Windows 11 与 Office

KMS_VL_ALL_AIO 免费上手指南:5分钟本地激活 Windows 11 与 Office 【免费下载链接】KMS_VL_ALL_AIO Smart Activation Script 项目地址: https://gitcode.com/gh_mirrors/km/KMS_VL_ALL_AIO 右下角的"未激活"水印赖了大半年,Office 里…

2026/8/22 15:29:49
kafka-examples 集成Avro与Schema Registry:KafkaAvroSerializer序列化全流程实战指南

kafka-examples 集成Avro与Schema Registry:KafkaAvroSerializer序列化全流程实战指南

kafka-examples 集成Avro与Schema Registry:KafkaAvroSerializer序列化全流程实战指南 【免费下载链接】kafka-examples Snippets and small examples demonstrating kafka features and configs 项目地址: https://gitcode.com/gh_mirrors/kaf/kafka-examples …

2026/8/22 15:29:49
Duster 风格指南全解读:Tighten 团队沉淀的 Laravel 代码规范精华清单

Duster 风格指南全解读:Tighten 团队沉淀的 Laravel 代码规范精华清单

Duster 风格指南全解读:Tighten 团队沉淀的 Laravel 代码规范精华清单 【免费下载链接】duster Automatic configuration for Laravel apps to apply Tightens standard linting & code standards. 项目地址: https://gitcode.com/gh_mirrors/du/duster …

2026/8/22 15:29:49
RDAP与传统Whois怎么选?用ipwhois前必须知道的6个核心区别

RDAP与传统Whois怎么选?用ipwhois前必须知道的6个核心区别

RDAP与传统Whois怎么选?用ipwhois前必须知道的6个核心区别 【免费下载链接】ipwhois Retrieve and parse whois data for IPv4 and IPv6 addresses 项目地址: https://gitcode.com/gh_mirrors/ip/ipwhois RDAP与传统Whois怎么选?这是每个用 ipwho…

2026/8/22 15:29:49
PCSX2调试器实战教程:用反汇编与断点逆向分析PS2游戏的完整指南

PCSX2调试器实战教程:用反汇编与断点逆向分析PS2游戏的完整指南

PCSX2调试器实战教程:用反汇编与断点逆向分析PS2游戏的完整指南 【免费下载链接】pcsx2 PCSX2 - The Playstation 2 Emulator 项目地址: https://gitcode.com/gh_mirrors/pcsx24/pcsx2 PCSX2 是最主流的 PlayStation 2 模拟器,而内置的 PCSX2 调试…

2026/8/22 15:24:49