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. Object-C语言Block的实现方式

    开场白 Block基本概念 中间态转换方法 Block编译后结果分析 Block运行时状态与编译状态对比   开场白   Object-C语言是对C语言的扩展,所以将OC源码进行编译的时候,会将OC源 ...

  2. JavaScript初级面试题

    前面几题是会很基础,越下越有深度. 初级Javascript: 1.JavaScript是一门什么样的语言,它有哪些特点? 没有标准答案. 2.JavaScript的数据类型都有什么? 基本数据类型: ...

  3. 在LaTeX中配置西夏文字体与环境

    目录 1 配置字族 2 粗体.斜体设定 3 文本编辑器的字体设定(以Sublime Text为例) 4 附录:一些字体的下载源 警告:这篇文章的部分内容需要西夏文字体才能正常显示.若您需要安装,可参考 ...

  4. HTML5的拖放事件

    1.给标签添加属性draggable=ture即可允许拖放,有些标签可以不加,例如img有图片.a有url,默认拥有拖放功能 2.事件在被拖动元素上触发 ondragstart ondrag ondr ...

  5. [CQOI 2018]解锁屏幕

    Description 题库链接 给出平面上 \(n\) 个点,一开始你可以选任何一个点作为起点,接着对于每一个你在的位置,你可以选取一个未走过的点.将路径(线段)上所有的点均选上(包括起点终点),并 ...

  6. FileStream文件的使用

    // FileStream//(操作字节的)水一勺一勺的 可以操作任意格式的文件           //File一下子就读出来 //读取文本文件 // FileMode.OpenOrCreate你针 ...

  7. 测试使用highlight.js的代码效果

    ---恢复内容开始--- C#代码 private void NextDateUpdate(DateTime dtt) { dtt.AddDays(); Response.Write("dt ...

  8. 一:Web

    一:Web介绍 1.Web:网页,网络 2.Web应用:运行在网络上的应用程序 3.网络应用程序分类:C/S B/S C/S 客服端(client)/服务器(server) 典型应用:QQ,YY B/ ...

  9. 手把手教你写一个java的orm(完)

    生成sql:select 上一篇讲了怎样生成一个sql中where的一部分,之后我们要做事情就简单很多了,就只要像最开始一样的生成各种sql语句就好了,之后只要再加上我们需要的条件,一个完整的sql就 ...

  10. 使用springcloud gateway搭建网关(分流,限流,熔断)

    Spring Cloud Gateway Spring Cloud Gateway 是 Spring Cloud 的一个全新项目,该项目是基于 Spring 5.0,Spring Boot 2.0 和 ...