可设置指定时间自动消失的 MessageBox实现
来源:互联网 发布:算法导论视频 百度网盘 编辑:程序博客网 时间:2024/04/30 00:16
本文主要是讲如何实现可设置指定时间自动消失的 MessageBox提示框ShowMessageBoxTimeout实现;
在开发客户端应用程序的时候,经常用得WinForm中MessageBox提示框。但是有时候还是满足不了一些用户要求,客户要求千奇百怪,例如客户需要做某些提示的时候,不去点击确定或取消的时候,等待一段时间自动消失,为此我们可以使用下面类来实现,采用 Thread.Sleep来关掉当前提示框,具体代码如下:
ShowMessageBoxTimeout实现
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.InteropServices;using System.Windows.Forms;using System.Threading;namespace Tools.App{ public class ShowMsg { [DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] static extern bool EndDialog(IntPtr hDlg, out IntPtr nResult); //三个参数:1、文本提示-text,2、提示框标题-caption,3、按钮类型-MessageBoxButtons ,4、自动消失时间设置-timeout public static void ShowMessageBoxTimeout(string text, string caption, MessageBoxButtons buttons, int timeout) { ThreadPool.QueueUserWorkItem(new WaitCallback(CloseMessageBox), new CloseState(caption, timeout)); MessageBox.Show(text, caption, buttons); } private static void CloseMessageBox(object state) { CloseState closeState = state as CloseState; Thread.Sleep(closeState.Timeout); IntPtr dlg = FindWindow(null, closeState.Caption); if (dlg != IntPtr.Zero) { IntPtr result; EndDialog(dlg, out result); } } }}
ShowMessageBoxTimeout调用
//三个参数:1、文本提示,2、提示框标题,3、按钮类型,4、自动消失时间设置ShowMsg.ShowMessageBoxTimeout("欢迎使用数据导出服务程序,本程序默认最小化到电脑托盘,1分钟后正式启动。", "程序启动温馨提示-窗口1分钟内无操作会自动关闭", MessageBoxButtons.OK, 1000 * 60 * 1);
希望以上分享对初学朋友有些帮助,谢谢!
更多关注付义方技术博客:http://blog.csdn.net/fuyifang
或者直接用手机扫描二维码查看更多博文:
1 0
- 可设置指定时间自动消失的 MessageBox实现
- UIScrollView 实现广告栏的无限轮播(可设置自动播放时间)
- div 指定时间消失
- 创建一个可定时自动关闭的MessageBox
- iOS中可以设定时间自动消失提示框的三种实现方式
- VPN的自动拨号程序,断线自动重拨,可设置断线重播得时间
- UIAlertView 实现自动消失
- WinForm 下实现一个自动关闭的MessageBox
- WinForm 下实现一个自动关闭的MessageBox
- WinForm 下实现一个自动关闭的MessageBox
- WinForm中实现自动关闭的MessageBox(CSharp)
- WinForm 下实现一个自动关闭的MessageBox
- wince/WinForm下实现一个自动关闭的MessageBox
- WinForm 下实现一个自动关闭的MessageBox
- .NET-MessageBox延时一定时间自动关闭
- [转]winfrom让弹出的MessageBox在指定时间内自动销毁
- DFS--障碍在指定时间会消失
- 自动关闭MessageBox的实例
- laravel吐槽系列之一
- Python HAIL CAESAR (凯撒密码) 1
- 通过进程找到主窗口的句柄
- Oxygen xml editor 16.0 x86 crack
- 传指针和传指针引用的区别/指针和引用的区别(本质)
- 可设置指定时间自动消失的 MessageBox实现
- 慈善和宽容
- 机器学习算法(六):随机森林
- 主题模型TopicModel:通过gensim实现LDA
- 使用jemalloc(或tcmalloc)优化MYSQL(安装步骤)
- java PropertyDescriptor 应用及源码分析
- Hadoop之——HBase笔记
- Isomorphic Strings
- 寻找最近公共祖先