c#:
     ......
     DialogResult PrtYesOrNo = MessageBox.Show("是否打印", "打印提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
     ......
        不知道是否有自动关闭或定时关闭该消息框的实现方法。要实现的效果是在用户没有点击的情况下自动关闭该提示框以更加人性化。

解决方案 »

  1.   

    是什么环境下的啊?我这里有wince和winform环境下的
      

  2.   

    http://www.cnblogs.com/eaglet/archive/2009/07/25/1529920.html
      

  3.   

    我觉得只是这样还不行,MessageBox只有静态的Show函数,不能用实例显示,显示之后也只能单击确定才能关闭。
    最好自己编一个像MessageBox的窗体,就可以用timer控制了。
      

  4.   

    自己用窗口模拟,再用timer实现
      

  5.   

    public void ShowMessageBoxTimeout(string text, string caption, int timeout)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(CloseMessageBox),
                    new CloseState(caption, timeout));
                MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button2);
            }        private 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("coredll.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
            [DllImport("coredll.dll")]
            static extern bool EndDialog(IntPtr hDlg, out IntPtr nResult);        private class CloseState
            {
                private int _Timeout;
                public int Timeout
                {
                    get
                    {
                        return _Timeout;
                    }
                }            private string _Caption;
                public string Caption
                {
                    get
                    {
                        return _Caption;
                    }
                }            public CloseState(string caption, int timeout)
                {
                    _Timeout = timeout;
                    _Caption = caption;
                }
            } 使用时:
                    //提示框显示2秒钟后自动关闭
                    close_messageBox.ShowMessageBoxTimeout("发送完成!", "提示", 2000); 在winform下使用时,只需将coredll.dll改为win32.dll即可
      

  6.   

    win32.dll改为user32.dll
    可以了
    但是现在感觉还是用模式窗口的效果要好一些,兼容性好且易控制,感谢各位,开始结帖散分了。
      

  7.   

    无法加载 DLL“coredll.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。