C#实现倒计时关闭提示框功能实现倒计时关闭提示框功能
最近小编接到一个功能需要实现一个提示框并且能自动关闭的,看到这个需求真是懵了,四处搜集资料才搞
定,接下来通过本文给大家分享C#实现倒计时关闭提示框功能,感兴趣的朋友跟随小编一起看看吧
前两天实现某个功能需要做一个提示框 并且能够自动关闭的,就从网上搜了一个能够自动关闭的提示框 ,但由于我需要的场景
是不确定计时时间的,所以并没有使用到该窗体,但是我觉得可以留存备用 ,后边也把我这种倒计时的提示框用处还是很多的,用
于自动弹窗 自动关闭 ,虽然在我的项目中没有
其核心方法在 timer(TimerCallBack,Object,int32,int32) TimerCallBack 是一个委托 ,代表要执行的方法,其用途可以用在各个定时去调用方
法的场景,而且可以设置窗体的FormBorderStyle的属性为None,设置窗体边框和标题栏外观不显示.
using 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 NewuView.Mix
{
public partial class AutoCloseMessageBox : Form
{
public AutoCloseMessageBox()
{
InitializeComponent();
}
public void getMassage(string text)
{
label1.Text = text;
}
public void GetText(string caption)
{
this.Text = caption;
}
System.Threading.Timer _timeoutTimer;
string _caption;
评论0