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. libcurl 函数curl_easy_perform在release下崩溃的问题

    今天遇到一个很奇怪的问题: 工程中用到了libcurl, debug可以正常运行,release每次都崩溃,断到curl_easy_perform这一行.堆栈中也得不到有用信息,于是GOOGLE一番, ...

  2. Spring MVC CORS support

    使用详见: https://spring.io/blog/2015/06/08/cors-support-in-spring-framework 简单用法,在Controller 方法上加 @Cros ...

  3. draw: Could not use program error=0x505

    原因:Android的模拟器在ADT中调试运行AVD时速度太慢.也就是说创建的虚拟手机配置太好,电脑带不动. 解决办法:从新创建虚拟手机,是手机配置低一点,具体创建方法如下: 开始先点运行,也就是下图 ...

  4. html5 录制mp3音频,支持采样率和比特率设置

    13年的时候做过html5录音,一个问题是保存的wav格式文件很大,当初用了一个迂回的方式,上传到服务器后调用 lame 编码器转换,但由于文件大,上传较慢.不得不说,前端技术发展真是日新月异,有人实 ...

  5. 关于meta标签

    一.Meta标签中的format-detection属性及含义 意为:格式检测 或许你会有这样的经历:当你在制作手机端的页面中,点击了没有加任何链接的格式的数字时,这时手机会进行自动拔号提示操作! 禁 ...

  6. Twitter的分布式自增ID算法snowflake (Java版)

    概述 分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的. 有些时候我们希望能使用一种 ...

  7. ng-init,ng-controller,ng-model

    1.ng-init 用于初始化数据,跟在$scope插入数据一样,但是在配合repeat指令时候比较有用: <div ng-repeat="arrOuter in arr" ...

  8. rdlc报表大小设置

    参考:http://stackoverflow.com/questions/427730/how-to-limit-rdlc-report-for-one-page-in-a-pdf 主要设置为:报表 ...

  9. MongoDB(NoSQL) 入门

    一.简介 NoSQL数据库因其可扩展性使其变得越来越流行,利用NoSQL数据库可以给你带来更多的好处, MongoDB是一个用C++编写的可度可扩展性的开源NoSQL数据库. 本文主要讲述MongoD ...

  10. 设置secureCRT的鼠标右键为弹出文本操作菜单功能

    options菜单下的 global options 页面的 terminal 中的 mouse 子菜单对 paste  on  right button 的选项取消勾选即可.