自定义延时关闭弹窗,替代MesssageBox

1,新建一个窗体MessageForm,在里面加一个label控件和timer

自定义延时关闭弹窗,替代MesssageBox

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)
{
label1.Text = txt;
timer1.Interval = t;
timer1.Start();
}
}

3,在其他窗体调用:

    MessageForm mf = new MessageForm(, "输入参数有误");
mf.Show();
上一篇:浅析TCP/IP 协议


下一篇:Session的方法getSession() 与 getSession(boolean para)区别