【C#】提示框自动关闭
来源:互联网 发布:淘宝魅力惠旗舰店 编辑:程序博客网 时间:2024/06/05 14:36
第一步:新建一个类库,如图:
第二步:添加两个类,CloseState.cs和ShowMsg.cs,代码如下:
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Model{ public class CloseState { private int _Timeout; /// <summary> /// In millisecond /// </summary> public int Timeout { get { return _Timeout; } } private string _Caption; /// <summary> /// Caption of dialog /// </summary> public string Caption { get { return _Caption; } } public CloseState(string caption, int timeout) { _Timeout = timeout; _Caption = caption; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Runtime.InteropServices;using System.Text;using System.Threading;using System.Windows.Forms;namespace Model{ 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 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); } } }}
第三步:调用
Model.ShowMsg show = new Model.ShowMsg();show.ShowMessageBoxTimeout("密码修改成功", "温馨提示", MessageBoxButtons.OK, 1000); //单位毫秒
参考资料:
资料一:http://www.cnblogs.com/XGLSummer/archive/2012/09/06/2673334.html
资料二:http://blog.csdn.net/fuyifang/article/details/46447547
2 0
- 【C#】提示框自动关闭
- easyUI实现(alert)提示框自动关闭
- 提示 延时自动关闭
- sql关闭开启自动提示
- IE 7 不弹出提示框,自动关闭窗体
- 关闭input文本输入框的自动提示功能
- 可自动关闭的JS消息提示框
- js提示框,n秒后自动关闭
- 可自动关闭的JS消息提示框
- 基于JS和CSS的自动关闭动态提示框
- c#TextBox输入框自动提示、自动补全功能
- 关闭网页文本框自动提示功能
- 没有提示的网页自动关闭代码
- 彻底关闭IE的自动完成提示
- 谷歌浏览器关闭自动翻译提示
- js 定时自动关闭窗口不提示
- js弹出提示信息并自动关闭
- 关闭Eclipse光标悬浮自动提示
- stringify、parse、param、eval、serialize、serializeArray
- CornerStone的使用
- 汇编程序开发环境搭配
- Java_容器_Collection_结构图
- 交换机和路由器的原理和差异浅析
- 【C#】提示框自动关闭
- Android Studio apk 打包流程
- redis清空缓存
- 说说各种手机输入法的体验
- css定位
- Matlab函数解析
- 当java使用数据库的jar包时如何导出jar包(转改)
- [leetcode] 463. Island Perimeter 解题报告
- 全加器 Si和Ci的表达式