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);
            }
        }
    }
}

winform messagebox自动关闭的更多相关文章

  1. C# WinForm MessageBox弹窗倒计时的自动关闭

    [DllImport("user32.dll", EntryPoint = "FindWindow")]        private static exter ...

  2. C# MessageBox自动关闭

    本文以一个简单的小例子,介绍如何让MessageBox弹出的对话框,在几秒钟内自动关闭.特别是一些第三方插件(如:dll)弹出的对话框,最为适用.本文仅供学习分享使用,如有不足之处,还请指正. 概述 ...

  3. 设置MessageBox自动关闭

    通过设置定时器,让定时器的Tick事件模拟往MessageBox发送一个Enter按钮代替用鼠标点击MessageBox上的确定按钮,来实现MessageBox的自动关闭,实现代码如下: System ...

  4. WinForm MessageBox 提示对话框

    public class MessageUtil { /// <summary> /// 显示一般的提示信息 /// </summary> /// <param name ...

  5. winform messagebox 统一

    vb.net 里面有两种messagebox,一种是vb语言提供的msgbox,另一种是.net framework 提供的messagebox.在此统一使用messagebox. Warning,提 ...

  6. C# - WinFrm应用程序MessageBox自动关闭小实验

    概述 在程序中MessageBox弹出的对话框,用于向用户展示消息,这是一个模式窗口,可阻止应用程序中的其他操作,直到用户将其关闭.但是有时候在自动化程序中,如果弹出对话框,程序将会中断,等待人工的干 ...

  7. winform messageBox.Show()

    MessageBox.Show(" 5 个参数...... ",     " 亮仔提示",     MessageBoxButtons.OKCancel,    ...

  8. C#MessageBox 自动关闭窗口

    1:MessageBox弹出的模式窗口会先阻塞掉它的父级线程.所以我们可以考虑在MessageBox前先增加一个用于"杀"掉MessageBox窗口的线程.因为需要在规定时间内&q ...

  9. C# WinForm MessageBox.Show显示在窗体中间

    一.新建MessageBoxEx类,并添加以下代码. using System; using System.Windows.Forms; using System.Text; using System ...

随机推荐

  1. maven tomcat插件上传项目到tomcat服务器报错SEVERE: One or more listeners failed to start.

    以前觉了maven依赖设置很简单,就是将手动导入jar包转化为自动下载导入 但发现的一个问题, 在使用maven插件tomcat打包上传工具时 tomcat-maven-plugin <buil ...

  2. java HashMap源码分析(JDK8)

    这两天在复习JAVA的知识点,想更深层次的了解一下JAVA,所以就看了看JAVA的源码,把自己的分析写在这里,也当做是笔记吧,方便记忆.写的不对的地方也请大家多多指教. JDK1.6中HashMap采 ...

  3. google glog 使用方法

    #include <glog/logging.h> int main(int argc,char* argv[]) { google::ParseCommandLineFlags(& ...

  4. 页面常见布局以及实现方法--flex

    页面布局是前端工程师的基本功之一,总结分析各种布局实现方法,可以让自己快速定位哪种方法实现功能,同时可以做到现最大程度的兼容. 一.水平居中 假设:最基本机构 .parent>.child 1. ...

  5. TFS Negotiate方式登录的IIS配置

    使用vsts-agent连接到tfs(tfs2017)配置代理客户端,可以通过PAT.Negotiate.Integrated.Alternate四种方式登录.(参考) 默认情况下,采用Negotia ...

  6. FileStream类的使用(文件流)

    1.什么是FileStream类 FileStream 类对文件系统上的文件进行读取.写入.打开和关闭操作,并对其他与文件相关的操作系统句柄进行操作,如管道.标准输入和标准输出.读写操作可以指定为同步 ...

  7. 项目Debug版本与Release版本的区别

    Debug版本:通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序. Release版本:称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很 ...

  8. 浅谈一致性哈希(My转)

    一致性哈希(Consistent hashing)算法是由 MIT 的Karger 等人与1997年在一篇学术论文(<Consistent hashing and random trees: d ...

  9. Maven项目下启动后Eclipse报错:org.springframework.web.context.ContextLoaderListener

    严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderLis ...

  10. linux基础学习之软件安装以及常用命令(三)

    添加和查看用户: [root@localhost ~]# useradd anderson [root@localhost ~]# cat /etc/passwd 显示如下: [root@localh ...