欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > c#确定按钮5秒自动确定

c#确定按钮5秒自动确定

2025/6/22 4:19:37 来源:https://blog.csdn.net/JQLvopkk/article/details/147629720  浏览:    关键词:c#确定按钮5秒自动确定

       public static class MessageBoxAutoClose
        {
            // 引入Windows API函数
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

            [System.Runtime.InteropServices.DllImport("user32.dll")]
            private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);

            private const int WM_CLOSE = 0x0010;

            public static void Show(string message, string title, int delayMilliseconds)
            {
                System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                timer.Interval = delayMilliseconds;
                int coui = delayMilliseconds / 1000;
                timer.Tick += (sender, e) =>
                {
                    timer.Stop();
                    IntPtr mbWnd = FindWindow("#32770", title); // 根据标题查找消息框的窗口句柄
                    if (mbWnd != IntPtr.Zero)
                    {
                        SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); // 发送关闭消息框的消息
                    }
                };
                timer.Start();

                MessageBox.Show(message + "(" + coui + "秒自动确定)", title);
            }

        }

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词