如何使messagebox.show对话框,在3秒之后自动消失 C# RT实现messagebox.show对话框后,不手动点确定就一直存在着。如何实现在3秒后自动消失,用C#3Q~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/eaglet/archive/2009/07/24/1529920.html 给你找的篇博文,希望有用。 在窗体加载事件中写入如下内容System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();timer.Tick += new System.EventHandler(this.timer_Tick);timer.Interval = 3000;//3000毫秒timer.Enabled = true;//控件生效private void timer1_Tick(object sender, EventArgs e){//触发时间关闭窗体this.Close();} #region 提示框 自动关闭 public static void DisplayMsg(string sCaption, string sMsg, int timeout = 0) { //XtraMessageBox.Show(sMsg, sCaption); ThreadPool.QueueUserWorkItem(new WaitCallback(CloseMessageBox), new CloseState(sCaption, (timeout < 1000) ? 1000 : timeout)); // timeout,1000是毫秒 sMsg = sMsg.Replace("!", "").Replace("!", "") + "!"; MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2); } private static void CloseMessageBox(object state) { CloseState closeState = state as CloseState; Thread.Sleep(closeState.Timeout); IntPtr dlg = FindWindow(null, closeState.Caption); if (dlg != IntPtr.Zero) { IntPtr result; EndDialog(dlg, out result); } } [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] static extern bool EndDialog(IntPtr hDlg, out IntPtr nResult); #endregion在页面上的调用方法: DisplayMsg(this.Text,"hello world"); 了解一下c#中winform计时器…… 对listbox中的items进行筛选 急!急!急!怎样把datagridview表格编辑后把内容保存到excel中?? C# 在线播放.avi视频格式出现的问题 一个水晶报表的问题 这样的效果在c#中如何实现 谁能给我讲讲datagrid怎么用啊?100分 datatable置顶 菜鸟求助,如何调用外部控件? 急!!!将Dataset中的数据插入数据库表中怎样用事务处理? 我的帖子怎么都没人会????郁闷,放分!:< 关于图片文件dpi读取的问题。 sql在模糊查询的存储过程的时间类型怎么处理
timer.Tick += new System.EventHandler(this.timer_Tick);
timer.Interval = 3000;//3000毫秒
timer.Enabled = true;//控件生效
private void timer1_Tick(object sender, EventArgs e)
{
//触发时间关闭窗体
this.Close();
}
public static void DisplayMsg(string sCaption, string sMsg, int timeout = 0)
{
//XtraMessageBox.Show(sMsg, sCaption);
ThreadPool.QueueUserWorkItem(new WaitCallback(CloseMessageBox), new CloseState(sCaption, (timeout < 1000) ? 1000 : timeout)); // timeout,1000是毫秒
sMsg = sMsg.Replace("!", "").Replace("!", "") + "!";
MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2);
}
private static void CloseMessageBox(object state)
{
CloseState closeState = state as CloseState;
Thread.Sleep(closeState.Timeout);
IntPtr dlg = FindWindow(null, closeState.Caption); if (dlg != IntPtr.Zero)
{
IntPtr result;
EndDialog(dlg, out result);
}
}
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool EndDialog(IntPtr hDlg, out IntPtr nResult);
#endregion在页面上的调用方法: DisplayMsg(this.Text,"hello world");