RT
实现messagebox.show对话框后,不手动点确定就一直存在着。
如何实现在3秒后自动消失,用C#
3Q~

解决方案 »

  1.   

    http://www.cnblogs.com/eaglet/archive/2009/07/24/1529920.html 给你找的篇博文,希望有用。
      

  2.   

    在窗体加载事件中写入如下内容System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
    timer.Tick += new System.EventHandler(this.timer_Tick);
    timer.Interval = 3000;//3000毫秒
    timer.Enabled = true;//控件生效
    private void timer1_Tick(object sender, EventArgs e)
    {
    //触发时间关闭窗体
    this.Close();
    }
      

  3.   

           #region 提示框 自动关闭
           public static void DisplayMsg(string sCaption, string sMsg, int timeout = 0)
           {
               //XtraMessageBox.Show(sMsg, sCaption);
               ThreadPool.QueueUserWorkItem(new WaitCallback(CloseMessageBox), new CloseState(sCaption, (timeout < 1000) ? 1000 : timeout)); // timeout,1000是毫秒
               sMsg = sMsg.Replace("!", "").Replace("!", "") + "!";
               MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2);
           }
           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);
               }
           }
           [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);
           #endregion在页面上的调用方法: DisplayMsg(this.Text,"hello world");
      

  4.   

    了解一下c#中winform计时器……