MessageBox实现自动延时关闭
1,首先新建一个winform窗体:MessageForm,设置StartPosition属性为Manual,Location属性值-500, -500
主要是为了让MessageForm窗体不显示在页面上
2,窗体内代码如下:
public partial class MessageForm : Form { int t; string txt; /// <summary> /// 自定义弹窗 /// </summary> /// <param name="time">窗体消失时间</param> /// <param name="text">窗体提示内容</param> public MessageForm(int time, string text) { t = time; txt = text; InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { this.Close(); } private void MessageForm_Load(object sender, EventArgs e) { timer1.Interval = t; timer1.Enabled = true; MessageBox.Show(this, txt, "提示"); } }
3,调用:
new MessageForm(3000, "输入参数有误").Show();
参考:https://blog.csdn.net/zheqingzheqing/article/details/51855274