using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; namespace WindowsApplication1
{
public partial class AutoDeleteMessageBox : Form
{
[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); public const int WM_CLOSE = 0x10; public AutoDeleteMessageBox()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
StartKiller();
MessageBox.Show("3秒钟后自动关闭MessageBox窗口", "MessageBox");
} private void StartKiller()
{
Timer timer = new Timer();
timer.Interval = 3000; //3秒启动
timer.Tick += new EventHandler(Timer_Tick);
timer.Start();
} private void Timer_Tick(object sender, EventArgs e)
{
KillMessageBox();
//停止Timer
((Timer)sender).Stop();
} private void KillMessageBox()
{
//按照MessageBox的标题,找到MessageBox的窗口
IntPtr ptr = FindWindow(null, "MessageBox");
if (ptr != IntPtr.Zero)
{
//找到则关闭MessageBox窗口
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
}
}

  网络上淘到的方法,试验可用,注意需要引用 System.Runtime.InteropServices;命名空间

定时自动关闭messagebox的更多相关文章

  1. C#自动弹出窗口并定时自动关闭

    最近做个小项目,用到一个小功能:后台线程定时查询数据库,不符合条件的记录弹出消息提醒(在窗口最前面),并且过几秒钟再自动关闭弹出的窗口. 所以从网上找来资料,如下: WinForm 下实现一个自动关闭 ...

  2. c#自动关闭 MessageBox 弹出的窗口

    我们都知道,MessageBox弹出的窗口是模式窗口,模式窗口会自动阻塞父线程的.所以如果有以下代码: MessageBox.Show("内容',"标题"); 则只有关闭 ...

  3. c# winform 自动关闭messagebox 模拟回车

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

  4. c# 定时关闭 MessageBox 或弹出的模态窗口

    我们都知道,MessageBox弹出的窗口是模式窗口,模式窗口会自动阻塞父线程的.所以如果有以下代码: MessageBox.Show("内容',"标题"); 则只有关闭 ...

  5. 延时并自动关闭MessageBox

    信息提示框(MessageBox)是微软NET自带的一个用于弹出警告.错误或者讯息一类的“模式”对话框.此类对话框一旦开启,则后台窗体无法再被激活(除非当前的MessageBox被点击或者关闭取消). ...

  6. 【C#/WPF】窗体定时自动关闭

    需求:打开WPF项目后,展示3秒钟产品Logo后,进入主界面MainWindow.(类似于安卓应用打开时的闪屏页SplashPage) 思路:在进入MainWindow后新建一个Window窗体,窗体 ...

  7. WinForm中使MessageBox实现可以自动关闭功能

    WinForm 下我们可以调用MessageBox.Show 来显示一个消息对话框,提示用户确认等操作.在有些应用中我们需要通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net ...

  8. winform messagebox自动关闭

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

  9. C# 设定时间内自动关闭提示框

    通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net framework 没有为我们提供自动关闭MessageBox 的方法,要实现这个功能,我们需要使用Window API ...

随机推荐

  1. Codeforce 370J Bottles(动态规划-01背包)

    题目链接:http://codeforces.com/problemset/problem/730/J 题目大意:有n个杯子, 每个杯子有两个值一个是已装水量,一个是可装水量.从一个杯子向另一个杯子倒 ...

  2. sqlalchemy 大全

    SQLAchemy SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据API执行S ...

  3. java_method_下载导入模版

    //调用方法 upDown.download(request, response, request.getRealPath("")+"/output/BlackNumbe ...

  4. 各大浏览器 CSS3 和 HTML5 兼容速查表

    不知不觉中,支持 CSS3 和 HTML5 的浏览器变得越来越多,甚至包括最新版的 IE,当然,所谓支持仅仅是部分支持,因为 CSS3 和 HTML5 的W3C 规范都尚未形成.如果你现在就希望使用 ...

  5. [goa]golang微服务框架学习--安装使用

      当项目逐渐变大之后,服务增多,开发人员增加,单纯的使用go来写服务会遇到风格不统一,开发效率上的问题. 之前研究go的微服务架构go-kit最让人头疼的就是定义服务之后,还要写很多重复的框架代码, ...

  6. 用js将从后台得到的时间戳(毫秒数)转换为想要的日期格式

    得到后台从数据库中拿到的数据我们希望格式是 2016年10月25日 17时37分30秒 或者 2016/10/25 17:37:30 然而我们前台得到的却是一段数字(时间戳,毫秒数) 14773860 ...

  7. Linux学习(一):从图形界面进入命令行及命令行进入图形界面

    一.从图形界面进入命令行 最近脑洞大开,想接触一下linux.本人设备是win7,于是安了VMware(12.0.0)虚拟机,在安Linux(我用的CentOS 6.3 64)时不太会搞,跟据提示(英 ...

  8. 关于本地缓存localStorage

    localStorage的优势 1.localStorage拓展了cookie的4K限制 2.localStorage会可以将第一次请求的数据直接存储到本地,这个相当于一个5M大小的针对于前端页面的数 ...

  9. 2-2. Initializing Objects with Initializer Lists

    Using Uniform Initialization to Construct a vector #include <iostream> #include <vector> ...

  10. 隐藏weibview里面的部分h5

    private void initWebView(String url) { twoCode.loadUrl(url); WebSettings settings = twoCode.getSetti ...