WinForm 定时器 定时弹出提示框并关闭

   WinForm 定时器 定时弹出提示框并关闭

        #region 弹框提示并自动关闭 (目的:延迟拍照)

        /// <summary>
        /// 关闭标志
        /// </summary>
        private const int WM_CLOSE = 0x0010;

        /// <summary>
        /// 弹框标题, const 类型以便访问查找
        /// </summary>
        private const string WM_CLOSE_TITLE = "存储中...";

        /// <summary>
        /// 定时器回调函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimerCallBack(object sender, EventArgs e)
        {
            IntPtr ptr = DllUtil.FindWindow(null, WM_CLOSE_TITLE); // ** 调用本地方法查找弹框的窗体指针
            if (ptr != IntPtr.Zero)
            {
                DllUtil.PostMessage(ptr, WM_CLOSE, 0, 0); // ** 发送窗体关闭消息
            }
            ((System.Windows.Forms.Timer)sender).Stop(); // ** 计时器停止
        }

        /// <summary>
        /// 创建定时器( 用于关闭 "当前拍照第几张" 的提示框)
        /// </summary>
        private void StartCloseBoxTimer()
        {
            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = 500; // ** 提示框/拍照间隔时间 对应的毫秒
            timer.Tick += new EventHandler(TimerCallBack); // ** 到达指定延迟时间的回调函数
            timer.Start(); // ** 启动定时器
        }

        #endregion 弹框提示并自动关闭 (目的:延迟拍照)

   调用

for (int i = 0; i < 3; ++i)
{
    StartCloseBoxTimer(); /// ** 创建当前提示框的关闭定时器
    MessageBox.Show("第 " + (i + 1) + " 张,请稍后...", WM_CLOSE_TITLE);
}

  

猜你喜欢

转载自colin-davis.iteye.com/blog/2201838