/// <summary>
/// 自动关闭Messbox
/// </summary>
public class MessageBoxAutoClose
{
System.Threading.Timer _timeoutTimer;
string _caption;
public MessageBoxAutoClose(string text, string caption, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption);
}
public MessageBoxAutoClose(string text, string caption, MessageBoxButtons msgButton, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption, msgButton);
} public MessageBoxAutoClose(string text, string caption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption, msgButton, msgIcon);
} /// <summary>
/// 提示关闭
/// </summary>
/// <param name="text">显示提示内容</param>
/// <param name="caption">标题</param>
/// <param name="timeout">设定指定毫秒后关闭</param>
public static void Show(string text, string caption, int timeout = )
{
new MessageBoxAutoClose(text, caption, timeout);
}
/// <summary>
/// 提示关闭
/// </summary>
/// <param name="text">显示提示内容</param>
/// <param name="caption">标题</param>
/// <param name="msgButton">提示按钮</param>
/// <param name="timeout">设定指定毫秒后关闭</param>
public static void Show(string text, string caption, MessageBoxButtons msgButton, int timeout = )
{
new MessageBoxAutoClose(text, caption, msgButton, timeout);
}
/// <summary>
/// 提示关闭
/// </summary>
/// <param name="text">显示提示内容</param>
/// <param name="caption">标题</param>
/// <param name="msgButton">提示按钮</param>
/// <param name="msgIcon">提示图标</param>
/// <param name="timeout">设定指定毫秒后关闭</param>
public static void Show(string text, string caption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon, int timeout = )
{
new MessageBoxAutoClose(text, caption, msgButton, msgIcon, timeout);
} void OnTimerElapsed(object state)
{
IntPtr mbWnd = FindWindow(null, _caption);
if (mbWnd != IntPtr.Zero)
SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
_timeoutTimer.Dispose();
}
const int WM_CLOSE = 0x0010;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
}

自动关闭Messbox的更多相关文章

  1. 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。

    解决Mysql连接池被关闭  ,hibernate尝试连接不能连接的问题. (默认MySQL连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池. 所以系统发布第二天访问会 ...

  2. CentOS 7 防止端口自动关闭

    tl;dr firewall-cmd --permanent --zone=public --add-port=2888/tcp firewall-cmd --reload #重新载入服务 永久配置f ...

  3. js实现弹框及自动关闭

    <SCRIPT LANGUAGE="javascript"> < !-- window.open (''page.html'',''newwindow'',''h ...

  4. mysql event_scheduler运行一段时间后 自动关闭

    应该是你重启过电脑或重启过服务了.  SELECT * FROM mysql.event;SET GLOBAL event_scheduler = 1; -- 开启定时器 0:off 1:on SHO ...

  5. Bootstrap 模态框在用户点击背景空白处时会自动关闭

    问题: Bootstrap 模态框在用户点击背景空白处时,会自动关闭. 解决方法: 在HTML页面中编写模态框时,在div初始化时添加属性 aria-hidden=”true” data-backdr ...

  6. bootstrap下使用模态框,在模态框内输入框中回车时,模态框自动关闭的问题及解决方法

    使用bootstrap下模态框,构建表单提交页面,但是输入框中直接回车,本来是想执行一下验证,但是却导致模态框自动关闭了. 遇到这样的问题,只需要先禁止回车触发表单提交            $(do ...

  7. QNDataSet打印预览自动关闭问题

    问题:打印预览后,数据集自动关闭 解决: TQNDataSet = class(TFDMemTable) private protected procedure PSReset; override; ...

  8. 如何让电脑公司Win7系统自动关闭停止响应的程序

    在注册表编辑器窗口左侧,依次展开HKEY_CURRENT_USER\ControlPanel\Desktop,选中Desktop,在右边的窗口中选择AutoEndTasks,双击打开AutoEndTa ...

  9. 定时自动关闭messagebox

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

随机推荐

  1. 具体解释XML解析(一)—解析接口浅析

    在DRP项目中接触到了一个XML解析工具DOM4J,它作为解析工具的据说性能很优秀.可是刚刚接触解析工具不久,而且也没有使用过其它的解析工具.因此对于DOM4J的性能没有直接的感受(没有參照物).只是 ...

  2. OpenGL ES 3.0 Graphics Pipeline

    一:OpenGL ES 3.0 Graphics Pipeline  渲染管道如下图 1.Vertex Buffer/Arrays Objects的数据由应用程序传进来 2.由上图可以看到Textur ...

  3. java中log日志的使用(完全版)

    Commons_logging包 Apache通用日志包 他为Log4JLogger:NoOpLog:LogKitLogger:Jdk14Logger:AvalonLogger提供了一共通用的接口进行 ...

  4. linux 下的两种软件安装方式 —— 源码(编译、安装),编译好的二进制(直接安装)

    我们以 GPG(加密工具)为例来说明两种安装方式的区别: 源码(Source code releases,名称中则会含有src等说明信息,tarball:source),先编译再安装 GPU 的源码地 ...

  5. 无法连接虚拟设备 ide1:0,因为主机上没有相应的设备。您要在每次开启此虚拟机时都尝试连接此虚拟设备吗?

    转自:http://blog.51cto.com/thawliu/1704876 安装虚拟机时出现提示:无法连接虚拟设备 ide1:0,因为主机上没有相应的设备.您要在每次开启此虚拟机时都尝试连接此虚 ...

  6. swoole-简单的异步执行

    swoole-简单的异步执行 标签(空格分隔): php 理解 一个IO操作其实分成了两个步骤:发起IO请求和实际的IO操作. 阻塞IO和非阻塞IO的区别在于第一步,发起IO请求是否会被阻塞,如果阻塞 ...

  7. 132.try throw catch介绍

    #include <iostream> using namespace std; //try尝试执行,抛出throw,throw之后语句不再执行 //catch处理throw的异常 voi ...

  8. Html表单提交到Servlet输出到页面乱码

    Html使用的编码是UTF-8编码显示页面,之后使用form表单提交字段到Servlet中,Servlet将利用getParamer方法获得form提交的字段,之后通过Respone中的writer将 ...

  9. 每个人都能实现的vue自定义指令

    前文 先来bb一堆废话哈哈.. 用vue做项目也有一年多了.除了用别人的插件之外.自己也没尝试去封装指令插件之类的东西来用. 刚好最近在项目中遇到一个问题.(快速点击按钮多次触发多次绑定的方法),于是 ...

  10. UI布局【转】

    转载自: https://www.cnblogs.com/wangdaijun/p/5519459.html https://www.jianshu.com/p/f781c40df57c Good U ...