欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Winform 无边框窗体双击放大缩小

程序员文章站 2022-05-06 08:10:06
...

废话不多说,直接上代码(talk is cheap,show me the code)


       

    
        [DllImport("user32.dll")] //Namespace System.Runtime.InteropServices;
        public static extern bool ReleaseCapture(); //release the mouse capture from a window in the current thread 

        //Send the specified message to a window,
        //The SendMessage fuction  calls the window procedure for the specified window and dose not return until  the window procedure has processed the message
        [DllImport("user32.dll")]
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MAXIMIZE = 0xF030;
        public const int SC_RESTORE = 0xF120;

        private void btn_title_MouseDown(object sender, MouseEventArgs e)
        {
 
            if (e.Clicks == 2)
            {
                if (WindowState == FormWindowState.Maximized)
                {
                    // Restore the form
                    ReleaseCapture();
                    SendMessage(Handle, WM_SYSCOMMAND, SC_RESTORE, 0);
                }
                else if (WindowState == FormWindowState.Normal)
                {
                    //Maximize the form
                    ReleaseCapture();
                    SendMessage(Handle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
                }
            }
        }