如何使messagebox.show对话框,在3秒之后自动消失 C#

waterfisher2012 2012-01-05 11:23:03
RT
实现messagebox.show对话框后,不手动点确定就一直存在着。
如何实现在3秒后自动消失,用C#
3Q~
...全文
1552 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
Change_L 2012-01-05
  • 打赏
  • 举报
回复
自己做一个消息窗体控制关闭时间
刹怕雳 2012-01-05
  • 打赏
  • 举报
回复
在窗体加载事件中写入如下内容

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();
}
kerr_hua 2012-01-05
  • 打赏
  • 举报
回复
http://www.cnblogs.com/eaglet/archive/2009/07/24/1529920.html 给你找的篇博文,希望有用。
狗血大熊猫 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 shapali 的回复:]
在窗体加载事件中写入如下内容

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;//……
[/Quote]

果断加上this.dispose();
  • 打赏
  • 举报
回复
了解一下c#中winform计时器……
DSIOF3KIDSKTR 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zhangnan20100811 的回复:]

为什么那么复杂呢,直接睡眠3秒钟
[/Quote]
最糟糕的方式,考虑其它处理单元的感受了吗
nan19890418 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 shapali 的回复:]
在窗体加载事件中写入如下内容

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;//……
[/Quote]
可以试一下
xyzhuzhou 2012-01-05
  • 打赏
  • 举报
回复
为了下载 潜水
ZhangNan20100811 2012-01-05
  • 打赏
  • 举报
回复
为什么那么复杂呢,直接睡眠3秒钟
  • 打赏
  • 举报
回复
自己写一个委托就可以搞定这件事 如果要求再高 可以写一个自定义窗体
Lucky_Ninja 2012-01-05
  • 打赏
  • 举报
回复
还不如自己写一个……
熙风 2012-01-05
  • 打赏
  • 举报
回复
建议自己写一个
ijwsoft 2012-01-05
  • 打赏
  • 举报
回复
#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");
ayzen1988 2012-01-05
  • 打赏
  • 举报
回复
沒試過
DSIOF3KIDSKTR 2012-01-05
  • 打赏
  • 举报
回复
自己可以写一个

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧