定时自动关闭messagebox
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的更多相关文章
- C#自动弹出窗口并定时自动关闭
最近做个小项目,用到一个小功能:后台线程定时查询数据库,不符合条件的记录弹出消息提醒(在窗口最前面),并且过几秒钟再自动关闭弹出的窗口. 所以从网上找来资料,如下: WinForm 下实现一个自动关闭 ...
- c#自动关闭 MessageBox 弹出的窗口
我们都知道,MessageBox弹出的窗口是模式窗口,模式窗口会自动阻塞父线程的.所以如果有以下代码: MessageBox.Show("内容',"标题"); 则只有关闭 ...
- c# winform 自动关闭messagebox 模拟回车
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- c# 定时关闭 MessageBox 或弹出的模态窗口
我们都知道,MessageBox弹出的窗口是模式窗口,模式窗口会自动阻塞父线程的.所以如果有以下代码: MessageBox.Show("内容',"标题"); 则只有关闭 ...
- 延时并自动关闭MessageBox
信息提示框(MessageBox)是微软NET自带的一个用于弹出警告.错误或者讯息一类的“模式”对话框.此类对话框一旦开启,则后台窗体无法再被激活(除非当前的MessageBox被点击或者关闭取消). ...
- 【C#/WPF】窗体定时自动关闭
需求:打开WPF项目后,展示3秒钟产品Logo后,进入主界面MainWindow.(类似于安卓应用打开时的闪屏页SplashPage) 思路:在进入MainWindow后新建一个Window窗体,窗体 ...
- WinForm中使MessageBox实现可以自动关闭功能
WinForm 下我们可以调用MessageBox.Show 来显示一个消息对话框,提示用户确认等操作.在有些应用中我们需要通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net ...
- winform messagebox自动关闭
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- C# 设定时间内自动关闭提示框
通过程序来自动关闭这个消息对话框而不是由用户点击确认按钮来关闭.然而.Net framework 没有为我们提供自动关闭MessageBox 的方法,要实现这个功能,我们需要使用Window API ...
随机推荐
- wini -- FileSubmitByFTP
// winFtpPutFiles.cpp : Defines the entry point for the console application.// #include "stdafx ...
- asp.net mvc表单异步提交
html代码: @using (Html.BeginForm("xx", "xx", FormMethod.Post, new { enctype = &quo ...
- Linux下NFS服务器的搭建与配置
一.NFS服务简介 NFS 就是 Network FileSystem 的缩写,最早之前是由sun 这家公司所发展出来的. 它最大的功能就是可以透过网络,让不同的机器.不同的操作系统.可以彼此分享个别 ...
- lvs+keepalived+nginx实现高性能负载均衡集群
一.为什么要使用负载均衡技术? 1.系统高可用性 2. 系统可扩展性 3. 负载均衡能力 LVS+keepalived能很好的实现以上的要求,LVS提供负载均衡,keepalived提供健康检查, ...
- 关于MVC中View使用自定义方法
今天学习到了在MVC的View中使用自定义方法,很简单,下面分享一下. 1.首先在项目下面建立一个文件夹,用于存我们写的自定义方法. 2.在新建文件夹中新增一个类,命名随便取(最好还是和自定义方法关联 ...
- UNIX 系统调用函数errno返回值搜集(in updating )
当Unix系统级函数遇到错误时,它们会典型地返回-1,并设置全局整数变量errno来表示什么出错了 阅读redis源码的时候,发现如果对系统级函数出错时的errno比较熟悉,写起程序来会游刃有余不少. ...
- 有效提高win7电脑网速50倍
有效提高win7电脑网速50倍 目前有多少人在使用Windows7?据统计微软已成功售出3.5亿份正版操作系统,加上市场上流传以Win7旗舰版为首的盗版Win7系统下载,Win7激活次数可能已经超过1 ...
- KindleEditor上传文件报404
初步怀疑是iis配置的允许上传大小太小了,然后就修改了配置文件但是不起作用. 后来百度了下iis版本是7.5,然后就按照iis8 的配置: IIS8请求筛选模块被配置为拒绝超过请求内容长度,在&quo ...
- python json模块
import json dic = {"name":"liao","age":18} data = json.dumps(dic) #转化为 ...
- lua string的自定义分割字符串接口
-------------------------------------------------------------------- -- Create By SunC 2014/7/1 -- ...