c# 更改最大化按钮功能实现最大化时遮盖任务栏,点击Esc取消全屏

来源:互联网 发布:婚礼相册mv制作软件 编辑:程序博客网 时间:2024/05/22 09:42

更改最大化按钮功能实现最大化时遮盖任务栏。

        const int WM_SYSCOMMAND = 0x112;
        const int SC_CLOSE = 0xF060;
        const int SC_MINIMIZE = 0xF020;
        const int SC_MAXIMIZE = 0xF030;
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_SYSCOMMAND)
            {
                if (m.WParam.ToInt32() == SC_MAXIMIZE)
                    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            }
            base.WndProc(ref m);
        }

在这里只能定义消息循环了,resize事件是在最大化之后发生的,再设置this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None。不会遮盖任务栏,OnMaximumSizeChanged和OnDeactivate的重写也实现不了。或者是还没研究透彻,有会的告诉我一声,谢谢。

 

点击Esc取消全屏:

首先设置窗体的KeyPreview属性为true.然后添加如下代码:

 private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                if (this.WindowState == FormWindowState.Maximized)
                {
                    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
                    this.WindowState = FormWindowState.Normal;
                }
        }

原创粉丝点击