自动关闭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 ...
随机推荐
- Java知识点解析
JAVA 1:简述Java的基本历史 java起源于SUN公司的一个GREEN的项目,其原先目的是为家用消费电子产品 发送一个信息的分布式代码系统,通过发送信息控制电视机.冰箱等. 2:简单写出Jav ...
- CoreData 从入门到精通(六)模型版本和数据迁移
前面几篇文章中讲的所有内容,都是在同一个模型版本上进行操作的.但在真实开发中,基本上不会一直停留在一个版本上,因为需求是不断变化的,说不定什么时候就需要往模型里添加新的字段,添加新的模型,甚至是大规模 ...
- Linux就该这么学 20181003(第四章Vim/shell/测试条件)
参考链接https://www.linuxprobe.com/ vim文本编辑器 命令模式:控制光标移动,可对文本进行复制,黏贴,删除和查找工作 输入模式:正常的文本录入 末行模式:保存或退出文档,以 ...
- C++线程传参数
struct TThreadParam { LPVOID pThis; int visionIndex; }; class CMilTestDlg : public CDialog { // Cons ...
- Adobe ZXPInstaller 报错 Installation failed because of a file operation error.
1. Drag a ZXP file or click here to select a file. 拖放一个 zxp 文件或点击打开选择一个 zxp 文件来安装: 2. Installation f ...
- LeetCode 744. Find Smallest Letter Greater Than Target (时间复杂度O(n))
题目 太简单了,直接上代码: class Solution { public: char nextGreatestLetter(vector<char>& letters, cha ...
- vue如何给它的data值赋值
activeDisplay的值如何改变 用$set();方法 vm.$set('b', 2) 或者 Vue.set(data, 'c', 3) this.someObject = Object.ass ...
- 使用Python进行多线程检查.moe三位剩余有效域名
翻看博客看到一段不错的代码 虽然近期没有购买域名的需求 不过日后有购买域名的需求的话 稍作修改直接使用还是很方便的 import threading import requests import js ...
- C语言计算字符串数组中每个字符串出现的个数
unsigned int str_num(char *str[], int num[], int len) { int i, j; int count; int flag[len]; ; i < ...
- 嵌入式(C)笔试题
1 读程序段,回答问题 (a) int main(int argc,char *argv[]) { int c=9,d=0; c=c++%5; d=c; printf("d=%d\n&quo ...