winfrom 自动关闭 重新MessageBox.Show("Test");
复制代码 自动关闭
调用 AutoClosingMessageBox.Show("添加失败", "提示", 1000);
#region alert
public class AutoClosingMessageBox
{
System.Threading.Timer _timeoutTimer;
string _caption;
AutoClosingMessageBox(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 static void Show(string text, string caption, int timeout)
{
new AutoClosingMessageBox(text, caption, 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);
}
#endregion
winfrom 自动关闭 重新MessageBox.Show("Test");的更多相关文章
- C#自动弹出窗口并定时自动关闭
最近做个小项目,用到一个小功能:后台线程定时查询数据库,不符合条件的记录弹出消息提醒(在窗口最前面),并且过几秒钟再自动关闭弹出的窗口. 所以从网上找来资料,如下: WinForm 下实现一个自动关闭 ...
- 定时自动关闭messagebox
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- c#自动关闭 MessageBox 弹出的窗口
我们都知道,MessageBox弹出的窗口是模式窗口,模式窗口会自动阻塞父线程的.所以如果有以下代码: MessageBox.Show("内容',"标题"); 则只有关闭 ...
- WinForm中使MessageBox实现可以自动关闭功能
WinForm 下我们可以调用MessageBox.Show 来显示一个消息对话框,提示用户确认等操作.在有些应用中我们需要通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net ...
- C# MessageBox自动关闭
本文以一个简单的小例子,介绍如何让MessageBox弹出的对话框,在几秒钟内自动关闭.特别是一些第三方插件(如:dll)弹出的对话框,最为适用.本文仅供学习分享使用,如有不足之处,还请指正. 概述 ...
- 设置MessageBox自动关闭
通过设置定时器,让定时器的Tick事件模拟往MessageBox发送一个Enter按钮代替用鼠标点击MessageBox上的确定按钮,来实现MessageBox的自动关闭,实现代码如下: System ...
- winform messagebox自动关闭
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- c# winform 自动关闭messagebox 模拟回车
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 延时并自动关闭MessageBox
信息提示框(MessageBox)是微软NET自带的一个用于弹出警告.错误或者讯息一类的“模式”对话框.此类对话框一旦开启,则后台窗体无法再被激活(除非当前的MessageBox被点击或者关闭取消). ...
随机推荐
- 关于java8中的String
String 对象的不可变性 java8中的String只有2个属性value和hash,相关代码如下: /** The value is used for character storage. */ ...
- 微信小程序 请求签名接口超时 踩坑路。。
我们公司一般做开发都是先用测试机的接口调试功能,等功能都调试的差不多了,再换成线上的正式接口,因为正式接口要验证签名. 这几个功能都调试的差不多了,准备换成线上正式接口了,结果却出了问题,提示请求超时 ...
- js 跳转传递汉字参数
父界面: myChart.on('click', function (params) { var dataIndex = params.dataIndex; if(params.name != &qu ...
- 执行sudo命令时command not found的解决办法
问题的原因: 在编译sudo包的时候默认开启了- -with-secure-path选项. 方法1: sudo vim /etc/sudoers,并在文件内增加这么一行:Defaults secure ...
- 《Tsinghua os mooc》第1~4讲 启动、中断、异常和系统调用
资源 OS2018Spring课程资料首页 uCore OS在线实验指导书 ucore实验基准源代码 MOOC OS习题集 OS课堂练习 Piazza问答平台 暂时无法注册 疑问 为什么用户态和内核态 ...
- 《你必须知道的495个C语言问题》读书笔记之第15-20章:浮点数、风格、杂项
一.可变参数列表 1. Q:为什么调用printf前必须要包含<stdio.h>? A:为了把printf的正确原型说明引入作用域.例如,如果可变参数的调用比固定参数的调用效率低,编译器就 ...
- Ubuntu 16.04 安装vim8
1. 卸载旧版本vim sudo apt-get remove vim vim-runtime gvim sudo apt-get remove vim-tiny vim-common vim-gui ...
- Oracle的查询-分页查询
--Oracle中的分页 --rownum行号:当我们做select操作时候 --每查询出一行记录,就在该行加上一个行号 --行号从1开始,一次递增,不能跳着走 ----emp表工资倒叙排列后,每页5 ...
- Hadoop集群搭建-01前期准备
Hadoop集群搭建-05安装配置YARN Hadoop集群搭建-04安装配置HDFS Hadoop集群搭建-03编译安装hadoop Hadoop集群搭建-02安装配置Zookeeper Hado ...
- MySql设计表中的create_time和update_time字段
一般create_time和update_time字段的类型为datetime类型,长度为0