自动关闭Messbox
/// <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的更多相关文章
- 解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题。 (默认mysql连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池。系统发布第二天访问链接关闭问题。
解决Mysql连接池被关闭 ,hibernate尝试连接不能连接的问题. (默认MySQL连接池可以访问的时间为8小时,如果超过8小时没有连接,mysql会自动关闭连接池. 所以系统发布第二天访问会 ...
- CentOS 7 防止端口自动关闭
tl;dr firewall-cmd --permanent --zone=public --add-port=2888/tcp firewall-cmd --reload #重新载入服务 永久配置f ...
- js实现弹框及自动关闭
<SCRIPT LANGUAGE="javascript"> < !-- window.open (''page.html'',''newwindow'',''h ...
- mysql event_scheduler运行一段时间后 自动关闭
应该是你重启过电脑或重启过服务了. SELECT * FROM mysql.event;SET GLOBAL event_scheduler = 1; -- 开启定时器 0:off 1:on SHO ...
- Bootstrap 模态框在用户点击背景空白处时会自动关闭
问题: Bootstrap 模态框在用户点击背景空白处时,会自动关闭. 解决方法: 在HTML页面中编写模态框时,在div初始化时添加属性 aria-hidden=”true” data-backdr ...
- bootstrap下使用模态框,在模态框内输入框中回车时,模态框自动关闭的问题及解决方法
使用bootstrap下模态框,构建表单提交页面,但是输入框中直接回车,本来是想执行一下验证,但是却导致模态框自动关闭了. 遇到这样的问题,只需要先禁止回车触发表单提交 $(do ...
- QNDataSet打印预览自动关闭问题
问题:打印预览后,数据集自动关闭 解决: TQNDataSet = class(TFDMemTable) private protected procedure PSReset; override; ...
- 如何让电脑公司Win7系统自动关闭停止响应的程序
在注册表编辑器窗口左侧,依次展开HKEY_CURRENT_USER\ControlPanel\Desktop,选中Desktop,在右边的窗口中选择AutoEndTasks,双击打开AutoEndTa ...
- 定时自动关闭messagebox
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
随机推荐
- node08---EJS模版
四.模板引擎 <a href="<%= url %>"><img src="<%= imageURL %>" alt= ...
- RSA in .net and dotnet core
dotnet RSAParameters Struct https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography ...
- ElasticSearch Shard——本质上是做分布式扩展,副本对于集群的稳定性有很强的影响
什么是一个Shard? Shard就是一个Lucene Index,参照文章(深入理解Shard和Lucene Index). Index需要多少个Shard? 回答这个问题,我们需要先谈谈节点,一个 ...
- 1. Git-2.12.0-64-bit .exe下载
转自:https://blog.csdn.net/u011164906/article/details/59129835 之前一直用SVN最近接触git,Git-2.12.0-64-bit .exe文 ...
- Mysqldump逻辑备份与恢复
文档结构: mysqldump备份影响性能,可能会把内存里面的热数据给冲刷掉,5.7后,新增一个参数,innodb_buffer_pool_dump_pct,控制每个innodb_buffer中转存活 ...
- JavaScript中Array方法总览
title: JavaScript中Array方法总览 toc: true date: 2018-10-13 12:48:14 push(x) 将x添加到数组最后,可添加多个值,返回数组长度.改变原数 ...
- springMVC接受参数总结
springMVC接受参数分类及使用对应注解才能正确接受到参数,否则报400或者接受的参数值为null: 1.接受单个参数 @RequestParam 不需要转json串 2.接受一个实体 @Requ ...
- 从SQL注入谈数据访问层
什么是SQL注入? SQL注入就是应用程序的开发人员未预期的吧SQL语句传入到应用程序的过程,如果直接使用用户输入的值来构建SQL语句的应用程序是很可能会受到SQL注入攻击的.特别是基于浏览器的网络应 ...
- (转载)Android自定义ProgressDialog进度等待框
Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...
- 51nod 1402 最大值 3级算法题 排序后修改限制点 时间复杂度O(m^2)
代码: 题意,第一个数为0,相邻的数相差0或者1,有一些点有限制,不大于给定值,求这组数中可能的最大的那个数. 这题我们看一个例子:第5个数的限制为2 1 2 3 4 5 6 7 8 9 0 1 2 ...