您的位置:首页 > 编程语言 > C#

C#winform让用户点击关闭按钮时不允许关闭窗体

2011-10-29 15:24 281 查看
         /// <summary>

        /// 用户点击关闭按钮,重写窗体接收信息处理函数

        /// </summary>

        /// <param name="msg"></param>

        protected override void WndProc(ref Message msg)

        {

            const int WM_SYSCOMMAND = 0x112;//命令操作

            const int SC_CLOSE = 0xF060;//命令类型

            if (msg.Msg == WM_SYSCOMMAND && (int)msg.WParam == SC_CLOSE)

            {

                if (MessageBox.Show("不能直接关闭该窗口,缩小到任务栏中吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)

                {

                    //this.notifyIcon.Visible = true;

                    //this.Hide();

                    if (isSizeChanged != null)

                    {

                        isSizeChanged();

                    }

                    this.ShowInTaskbar = false;

                    this.notifyIcon.Visible = true;

                    this.Hide();

                }

                else

                {

                }

                return;

            }

            //如果不是我们要拒接的消息,我们就让窗体处理

            base.WndProc(ref msg);

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  任务 null
相关文章推荐