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. Python -- 数据结构实现

    1.堆栈(pyStack.py) class PyStack: def __init__(self, size=20): self.stack = [] self.size = size self.t ...

  2. 微信小程序开发-概述

    微信小程序开发-概述 一.小程序申请&APPID 登录微信平台申请成为小程序开发者,小程序不可直接使用服务号或订阅号的AppID,需要登录微信公众平台管理后台,在网站的"设置&quo ...

  3. Mac在终端用命令装载dmg文件

    今天碰到个问题,下载了一个dmg文件,然后双击/右键安装,一点反应都没有.一开始以为是电脑的缘故,重启,依旧没有反应,然后想到用终端装载试试. 打开终端,输入命令: hdiutil attach we ...

  4. vue view 表单验证正常逻辑

    <template> <Form ref="formInline" :model="formInline" :rules="rule ...

  5. 深入SpringBoot:自定义Endpoint(转)

    本文转自:https://www.jianshu.com/p/9fab4e81d7bb 最近在研究改写actuator的方式,这些放这里已备忘 Endpoint SpringBoot的Endpoint ...

  6. Java生成指定范围内的工具类

    /** * 生成[min, max]之间的随机整数 * * @param min 最小整数 * @param max 最大整数 * @return * @author jqlin */ private ...

  7. sqljdbc.jar 和 sqljdbc4.jar

    为了支持向后兼容以及可能的升级方案,JDBC Driver 2.0 在每个安装包中都包括 2 个 JAR 类库:sqljdbc.jar 和 sqljdbc4.jar. JAR 说明 sqljdbc.j ...

  8. Polymorphic form--多态表单

    一个ruby on rails项目,用户和公司的模型都有地址. 我要创建一个地址表,包含用户和公司表的引用,比直接做下去要好一点,这回让我的数据库设计保持干净. 我的第一印象是,这似乎很难实现,外面所 ...

  9. rails image_tag生成图片标签

    image_tag(source, options={}) Link Returns an HTML image tag for thesource. The source can be a full ...

  10. Spring AOP 的实现

    软件152 余建强 1 使用 API 实现 AOP 新建一个用户接口:UserService package com.cqvie.aop.api; public interface UserServi ...