/// <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. 蓝桥杯 - 带分数 (DFS)

      历届试题 带分数   时间限制:1.0s   内存限制:256.0MB        问题描写叙述 100 能够表示为带分数的形式:100 = 3 + 69258 / 714. 还能够表示为:10 ...

  2. JSP中动态include与静态include的区别介绍

    转自:https://m.jb51.net/article/43304.htm 动态INCLUDE 用法:<jsp:include page="included.jsp" f ...

  3. [JZOJ 5888] [NOIP2018模拟9.29] GCD生成树 解题报告 (最大生成树+公约数)

    题目链接: http://172.16.0.132/senior/#main/show/5888 题目: 题解: 思路是这样的:两个数的最大公约数一定不会比这两个数的任意一个数大.因此我们把权值相等的 ...

  4. 极客时间 Mysql实战45讲 07讲行锁功过:怎么减少行锁对性能的影响笔记 极客时间

    极客时间 Mysql实战45讲 07讲行锁功过:怎么减少行锁对性能的影响笔记 极客时间极客时间 Mysql实战45讲 07讲行锁功过:怎么减少行锁对性能的影响笔记 极客时间 笔记体会: 方案一,事务相 ...

  5. VS 2015 C#不能进入断点

    工程\属性\生成页面,去掉优化代码勾选.

  6. localStorage、sessionStorage的区别

    1.localStorage生命周期是永久的, sessionStorage生命周期为当前窗口或标签页,一旦窗口或标签页被永久关闭了,那么所有通过sessionStorage存储的数据也就被清空了. ...

  7. C++之易混淆知识点三---算法分析

    最近复习算法,感到有一丝丝忘记的困惑,赶紧记下来... 一.分治法 分治法的思想就是“分而治之”,很明显就是将规模比较庞大.复杂的问题进行分治,然后得到多个小模块,最好这些小模块之间是独立的,如果这些 ...

  8. Xshell调整终端显示的最大行数(缓冲区)

    1 选择会话,按顺序点击文件->属性 ,打开"会话属性"窗口 如下 在"会话属性"窗口中选择“终端” 修改缓冲区大小的值:其范围为0~2147483647 ...

  9. activity的23张表

    --二进制数据表 SELECT * FROM act_ge_bytearray; --属性数据表存储整个流程引擎级别的数据,初始化表结构时,会默认插入三条记录, SELECT * FROM act_g ...

  10. 存储Hyper-V虚拟机的硬盘空间不足时的处理

    存储Hyper-V虚拟机的硬盘空间严重不足时的处理   ==先导出虚拟机到空间足够的硬盘,再在空间足够的分区上导入虚拟机 方法如下: 导出虚拟机: 导出之前,我们先删除不需要的快照. 在Hyper-V ...