1,新建一個窗體MessageForm,在裡面加一個label控制項和timer 2,代碼如下: 3,在其他窗體調用: ...
1,新建一個窗體MessageForm,在裡面加一個label控制項和timer
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(3000, "輸入參數有誤"); mf.Show();