当前位置: 首页> 科技> 数码 > 哈尔滨seo网站排名_中国建筑工程网施工组织设计_百度一下百度一下百度一下_太原seo外包公司

哈尔滨seo网站排名_中国建筑工程网施工组织设计_百度一下百度一下百度一下_太原seo外包公司

时间:2025/7/11 23:15:28来源:https://blog.csdn.net/weixin_43050480/article/details/144277194 浏览次数:0次
哈尔滨seo网站排名_中国建筑工程网施工组织设计_百度一下百度一下百度一下_太原seo外包公司

C# GDI绘制的倒计时控件

using System;
using System.Drawing;
using System.Windows.Forms;public class CountdownControl : Control
{private Timer timer;private TimeSpan remainingTime;public CountdownControl(){this.timer = new Timer();this.timer.Interval = 1000; // 1 secondthis.timer.Tick += Timer_Tick;this.remainingTime = TimeSpan.FromMinutes(1); // Default countdown of 1 minute}private void Timer_Tick(object sender, EventArgs e){if (remainingTime > TimeSpan.Zero){remainingTime = remainingTime.Subtract(TimeSpan.FromSeconds(1));}else{timer.Stop();}this.Invalidate(); // Redraw the control}public void StartCountdown(TimeSpan duration){remainingTime = duration;timer.Start();}protected override void OnPaint(PaintEventArgs e){base.OnPaint(e);Graphics g = e.Graphics;// Clear the control with the background colorg.Clear(this.BackColor);// Draw the countdowng.DrawString($"{remainingTime:mm\\:ss}", this.Font, Brushes.Black, new PointF(0, 0));}
}// Usage example:
// CountdownControl countdown = new CountdownControl();
// countdown.StartCountdown(TimeSpan.FromMinutes(5)); // Start a 5 minute countdown
// this.Controls.Add(countdown);
关键字:哈尔滨seo网站排名_中国建筑工程网施工组织设计_百度一下百度一下百度一下_太原seo外包公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: