博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自动关闭Messbox
阅读量:6877 次
发布时间:2019-06-26

本文共 2814 字,大约阅读时间需要 9 分钟。

///     /// 自动关闭Messbox    ///     public class MessageBoxAutoClose    {        System.Threading.Timer _timeoutTimer;        string _caption;        public MessageBoxAutoClose(string text, string caption, int timeout)        {            _caption = caption;            _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,                null, timeout, System.Threading.Timeout.Infinite);            MessageBox.Show(text, caption);        }        public MessageBoxAutoClose(string text, string caption, MessageBoxButtons msgButton, int timeout)        {            _caption = caption;            _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,                null, timeout, System.Threading.Timeout.Infinite);            MessageBox.Show(text, caption, msgButton);        }        public MessageBoxAutoClose(string text, string caption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon, int timeout)        {            _caption = caption;            _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,                null, timeout, System.Threading.Timeout.Infinite);            MessageBox.Show(text, caption, msgButton, msgIcon);        }        ///         /// 提示关闭        ///         /// 显示提示内容        /// 标题        /// 设定指定毫秒后关闭        public static void Show(string text, string caption, int timeout = 2000)        {            new MessageBoxAutoClose(text, caption, timeout);        }        ///         /// 提示关闭        ///         /// 显示提示内容        /// 标题        /// 提示按钮        /// 设定指定毫秒后关闭        public static void Show(string text, string caption, MessageBoxButtons msgButton, int timeout = 2000)        {            new MessageBoxAutoClose(text, caption, msgButton, timeout);        }        ///         /// 提示关闭        ///         /// 显示提示内容        /// 标题        /// 提示按钮        /// 提示图标        /// 设定指定毫秒后关闭        public static void Show(string text, string caption, MessageBoxButtons msgButton, MessageBoxIcon msgIcon, int timeout = 2000)        {            new MessageBoxAutoClose(text, caption, msgButton, msgIcon, timeout);        }        void OnTimerElapsed(object state)        {            IntPtr mbWnd = FindWindow(null, _caption);            if (mbWnd != IntPtr.Zero)                SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);            _timeoutTimer.Dispose();        }        const int WM_CLOSE = 0x0010;        [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);    }

 

转载于:https://www.cnblogs.com/randyzhuwei/p/4058715.html

你可能感兴趣的文章
PHP获得真实客户端的真实IP REMOTE_ADDR,HTTP_CLIENT_IP,HTTP_X_FORWARDED_FOR
查看>>
poj1323
查看>>
c getline
查看>>
linux下拷贝的时候有时候会出现cp:omitting directory的错误
查看>>
C#简单的多线程
查看>>
HTML转换成字符串
查看>>
关于使用CTE(公用表表达式)的递归查询
查看>>
C#简单的面试题目(五)
查看>>
讲故事学Socket编程
查看>>
ural(Timus) 1037. Memory Management
查看>>
jquery实现菜单的折叠并且变换图片
查看>>
微信公众平台消息接口开发(27)彩票查询
查看>>
hdu 1829+hdu 1856(并查集)
查看>>
WIN32 DLL动态链接库
查看>>
用vmware运行简单的引导代码
查看>>
WPF中资源文件的使用
查看>>
Request 分别获取具有相同 name 属性表单元素值
查看>>
错误码:2003 不能连接到 MySQL 服务器在 (10061)
查看>>
js判断文件格式及大小
查看>>
如何确定当前的PowerShell的版本?
查看>>