当前位置:网站首页>C# 倒计时工具
C# 倒计时工具
2022-07-28 09:17:00 【biyusr】
最近一个朋友在玩一个网络游戏,游戏里有10多个小头目,小头目死后每10分钟刷新一次。有好多玩家抢着打怪,谁第一次有伤害,boss死后物品归谁,朋友苦于计算不到小头目boss准备刷新的时间。总是抢不赢别人。想由我帮他弄个多点计算倒计的时间软件。我无聊觉可行,说干就干。
软件界面由:2个按钮(添加、删除)、一个listView,一个pictureBox,一个timer时钟组成。

Dotnet工控
专注分享DotNET编程经验,挖掘程序员优秀的学习资源。
7篇原创内容
公众号

启动时需设计listView列: 只能选择整行需设计listView1.FullRowSelect为True,设计timer为计算倒计时,以秒为单位。
private void Form1_Load(object sender, EventArgs e){comboBox1.SelectedIndex = 0;listView1.Columns.Add("倒计时/秒",80,HorizontalAlignment.Left);listView1.Columns.Add("定时间");listView1.Columns.Add("图片地址", 100, HorizontalAlignment.Left);listView1.FullRowSelect = true;//只能选一行timer1.Interval = 1000;timer1.Start();}
2. 添加按钮,载图并且保存图片,方便下次查看。
private void button1_Click(object sender, EventArgs e){pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;//图片拉升或缩小,适应picture控件string url;保存图片地址pictureBox1.Image = GetScreenCapture(out url); //用方法载图ListViewItem listViewItem = new ListViewItem();string timeritem = System.Text.RegularExpressions.Regex.Replace(comboBox1.Text, @"[^0-9]+", ""); //求数字listViewItem.Text = (int.Parse(timeritem)*60).ToString();listViewItem.SubItems.Add($"{comboBox1.Text}");listViewItem.SubItems.Add(url);listView1.Items.Add(listViewItem);}private Bitmap GetScreenCapture(out string url){Rectangle tScreenRect = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);Bitmap tSrcBmp = new Bitmap(tScreenRect.Width, tScreenRect.Height); // 用于屏幕原始图片保存Graphics gp = Graphics.FromImage(tSrcBmp);gp.CopyFromScreen(0, 0, 0, 0, tScreenRect.Size);gp.DrawImage(tSrcBmp, 0, 0, tScreenRect, GraphicsUnit.Pixel);Random ran = new Random();url = @$"temp\{ran.Next(1, 999)}.jpg";tSrcBmp.Save(url);return tSrcBmp;}
3.需按秒更新倒计时,在timer时钟里更新全部的倒计时,
private void timer1_Tick(object sender, EventArgs e){this.listView1.BeginUpdate(); //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度foreach (ListViewItem item in listView1.Items){item.SubItems[0].Text = (int.Parse(item.SubItems[0].Text) - 1).ToString();}this.listView1.EndUpdate(); //结束数据处理,UI界面一次性绘制。}/// <summary>/// 双击显示图片/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void listView1_MouseDoubleClick(object sender, MouseEventArgs e){pictureBox1.ImageLocation = listView1.SelectedItems[0].SubItems[2].Text;}/// <summary>/// 删除/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button2_Click(object sender, EventArgs e){File.Delete(listView1.SelectedItems[0].SubItems[2].Text);listView1.SelectedItems[0].Remove();}
4.效果图:朋友很满意,能计算到小头目秒刷新。快到倒计时为10秒时就赶快到那要刷新的地点等小头目。总是能抢到小头目

5.事后又找我能否帮他弄个自动打怪抢头目的脚本,我怕了他了

,直接跟他说不会。
边栏推荐
- 21天学习挑战赛-《Autosar从入门到精通-实战篇》
- HashSet内部原理解析
- Analysis of HashSet internal principle
- 软件测试与质量学习笔记1---黑盒测试
- MySQL 8.0.30 GA
- Opencv installation configuration test
- What is it like to use gbase C API to execute stored procedures?
- [Guangxi University] information sharing of postgraduate entrance examination and re examination
- IntelliJ idea associated database
- With such a simple verification, 80% of programmers can't do it, let alone understand it!
猜你喜欢

Business visualization - make your flowchart'run'(4. Actual business scenario test)

Introduction to shardingsphere's concept of sub database and sub table (2)

IDC script file running

对话MySQL之父:代码一次性完成才是优秀程序员

Introduction to SD card (based on spec3.0)

The maximum recommended number of rows for MySQL is 2000W. Is it reliable?

Detailed explanation of various types of files in MySQL

《我的Vivado实战—单周期CPU指令分析》

Regular expressions for positive and negative values

MQ learning
随机推荐
MATLAB的实时编辑器
C signed and unsigned byte variables
CakePHP 4.4.3 release, PHP rapid development framework
数据库高级学习笔记--对象类型
[swintransformer source code reading II] window attention and shifted window attention
How to learn so many conceptual things in database? Seeking method
Opencv installation configuration test
2.9.5 Ext JS的Object类型处理及便捷方法
[C language] detailed explanation sequence table (seqlist)
可以伸缩的搜索栏,模仿华为应用市场
IJCAI 2022 | 图结构学习最新综述:研究进展与未来展望
SD卡介绍(基于SPEC3.0)
Business visualization - make your flowchart'run'(4. Actual business scenario test)
[multithreading] non atomic agreement of long and double
ARouter源码解析(二)
Analysis of the internal principle of LinkedList
业务可视化-让你的流程图'Run'起来(4.实际业务场景测试)
ARouter源码解析(一)
Dn-detr paper accuracy, and analyze its model structure & 2022 CVPR paper
Inside database system distributed system