添加一个类库MessageBoxTimeOut

   public class MessageBoxTimeOut
{
private string _caption; public void Show(string text, string caption)
{
Show(, text, caption);
}
public void Show(int timeout, string text, string caption)
{
Show(timeout, text, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public void Show(int timeout, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
this._caption = caption;
StartTimer(timeout);
MessageBox.Show(text, caption, buttons, icon);
}
private void StartTimer(int interval)
{
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = interval;
timer.Tick += new EventHandler(Timer_Tick);
timer.Enabled = true;
}
private void Timer_Tick(object sender, EventArgs e)
{
KillMessageBox();
//停止计时器
((System.Windows.Forms.Timer)sender).Enabled = false;
}
[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;
private void KillMessageBox()
{
//查找MessageBox的弹出窗口,注意对应标题
IntPtr ptr = FindWindow(null, this._caption);
if (ptr != IntPtr.Zero)
{
//查找到窗口则关闭
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
}

调用

      MessageBoxTimeOut mb = new MessageBoxTimeOut();
mb.Show("产品编码不存在!", "提示(窗体3秒后自动关闭...)");

winform 关于Messagebox自动定时关闭的更多相关文章

  1. QMessage自动定时关闭

    QMessageBox *box = new QMessageBox(QMessageBox::Information,tr("test"),tr("testtest&q ...

  2. Messagebox自定义计时关闭

    Messagebox自定义计时关闭 新建Winform项目WindowsFormsAppTESTMessageBoxAutoClose 主窗体代码 using System;using System. ...

  3. winform软件版本检测自动升级开发流程(转)

    注:按此博文试验OK 基于C/S的开发有开发效率高,对于业务逻辑复杂,且不需要外网使用具有较大优势,但是弊端也不可忽视,就是升级麻烦,不可能每写一个版本就要拿着安装包给每个人去替换,这样不仅搞得自己很 ...

  4. CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存

    CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存来自:互联网 时间:2020-03-22 阅读:114以下情况可能造成Linux内存占用过高服务配置存在直接分配错误,或隐性分 ...

  5. C# WinForm 中 MessageBox的使用详解

    1.C# WinForm 中 MessageBox的使用详解:http://www.cnblogs.com/bq-blog/archive/2012/07/27/2611810.html

  6. 【温故而知新-Javascript】窗口效果 (全屏显示窗口、定时关闭窗口)

    1.全屏显示窗口 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  7. [转]mysql自动定时备份数据库的最佳方法-支持windows系统

    网上有很多关于window下Mysql自动备份的方法,可是真的能用的也没有几个,有些说的还非常的复杂,难以操作. 我们都知道mssql本身就自带了计划任务可以用来自动备份,可是mysql咱们要怎么样自 ...

  8. windows系统——mysql自动定时备份数据库的最佳方法

    网上有很多关于window下Mysql自动备份的方法,可是真的能用的也没有几个,有些说的还非常的复杂,难以操作. 我们都知道mssql本身就自带了计划任务可以用来自动备份,可是mysql咱们要怎么样自 ...

  9. SQL2008实现数据库自动定时备份——维护计划

    在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库.而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求管理员 每天守到晚上1点去备份数据库.要实现数据库的 ...

随机推荐

  1. gitlab的md文件内使用锚点

    markdown中使用锚点的格式: [要显示的内容](#锚点的链接) 如: [工具](#tool) 又因为再markdown中每一个标题都默认是锚点,所以事情就简单了 # test ## conten ...

  2. jQuery实用Demo

    1.点击 隐藏/显示 元素 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  3. C# 1.0 到 4.0 的进化 1

    定义一个产品类 Product C# 1 using System; using System.Collections; namespace C1 { public class Product { s ...

  4. B 树、B+ 树、B* 树

    B 树.B+ 树.B* 树 作者:July.weedge.Frankie.编程艺术室出品. 说明:本文从B树开始谈起,然后论述B+树.B*树,最后谈到R 树.其中B树.B+树及B*树部分由weedge ...

  5. SOA和微服务架构的区别?

    转自知乎:https://www.zhihu.com/question/37808426/answer/93335393 SOA和微服务架构的区别? 微服务架构强调的第一个重点就是业务系统需要彻底的组 ...

  6. (转) C# Async与Await的使用

    (转) C# Async与Await的使用 class Program { static void Main(string[] args) { Console.WriteLine("主线程测 ...

  7. Dubbox分布式框架

    一:简介:前身是阿里巴巴的一个开源的项目,后来停止维护,由当当网继续维护,它致力于rpc远程的调度方案.是一个服务框架 二:执行原理图: 节点角色说明: · Provider: 暴露服务的服务提供方. ...

  8. Power of Matrix(uva11149+矩阵快速幂)

    Power of Matrix Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit St ...

  9. Saving HDU(hdu2111,贪心)

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  10. Java - TreeSet源码解析

    Java提高篇(二八)------TreeSet 与HashSet是基于HashMap实现一样,TreeSet同样是基于TreeMap实现的.在<Java提高篇(二七)-----TreeMap& ...