zoukankan      html  css  js  c++  java
  • 无边框窗体设置

    #region 方法:无边框拖动窗体
            Point mouseOff;//鼠标移动位置变量
            bool RightFlag;//标签是否为左键
            private void groupMenu_MouseUp(object sender, MouseEventArgs e)
            {
                if (RightFlag)
                {
                    RightFlag = false;//释放鼠标后标注为false;
                }
    
            }
    
            private void groupMenu_MouseMove(object sender, MouseEventArgs e)
            {
                if (RightFlag)
                {
                    Point mouseSet = Control.MousePosition;
                    mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                    Location = mouseSet;
                }
            }
    
            private void groupMenu_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                    RightFlag = true;                  //点击左键按下时标注为true;
                }
                //MouseDown_ResizeForm(this);
            }
            #endregion
    #region 两边阴影
            private const int CS_DropSHADOW = 0x20000;
            private const int GCL_STYLE = (-26);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int GetClassLong(IntPtr hwnd, int nIndex);
    
            private void SetShadow()
            {
                SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
            } 
            #endregion
    #region 四边阴影
            [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
            private static extern IntPtr CreateRoundRectRgn
                        (
                            int nLeftRect,
                            int nTopRect,
                            int nRightRect,
                            int nBottomRect,
                            int nWidthEllipse,
                            int nHeightEllipse
                         );
    
            [DllImport("dwmapi.dll")]
            public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
    
            [DllImport("dwmapi.dll")]
            public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
    
            [DllImport("dwmapi.dll")]
            public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
    
            private bool m_aeroEnabled;
            private const int CS_DROPSHADOW = 0x00020000;
            private const int WM_NCPAINT = 0x0085;
            private const int WM_ACTIVATEAPP = 0x001C;
    
            public struct MARGINS
            {
                public int leftWidth;
                public int rightWidth;
                public int topHeight;
                public int bottomHeight;
            }
    
            private const int WM_NCHITTEST = 0x84;
            private const int HTCLIENT = 0x1;
            private const int HTCAPTION = 0x2;
    
            protected override CreateParams CreateParams
            {
                get
                {
                    m_aeroEnabled = CheckAeroEnabled();
    
                    CreateParams cp = base.CreateParams;
                    if (!m_aeroEnabled)
                        cp.ClassStyle |= CS_DROPSHADOW;
    
                    return cp;
                }
            }
    
            private bool CheckAeroEnabled()
            {
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    int enabled = 0;
                    DwmIsCompositionEnabled(ref enabled);
                    return (enabled == 1) ? true : false;
                }
                return false;
            }
    
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case WM_NCPAINT:
                        if (m_aeroEnabled)
                        {
                            var v = 2;
                            DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
                            MARGINS margins = new MARGINS()
                            {
                                bottomHeight = 1,
                                leftWidth = 1,
                                rightWidth = 1,
                                topHeight = 1
                            };
                            DwmExtendFrameIntoClientArea(this.Handle, ref margins);
    
                        }
                        break;
                    default:
                        break;
                }
                base.WndProc(ref m);
    
                if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)     // drag the form
                    m.Result = (IntPtr)HTCAPTION;
    
            }
            #endregion
  • 相关阅读:
    ES 分词器简单应用
    ElasticSearch 通过 Kibana 与 ElasticSearch-head 完成增删改查
    linux 通过docker安装 elasticsearch-head
    The container name "/nacos" is already in use by container
    mysql 用户及用户权限管理命令总结-用户添加及添加权限
    docker 安装 ElasticSearch 和 Kibana 及ik 中文分词器
    docker 安装 nacos
    mysql 主从状态查询及恢复
    那些看似牛逼的「快速阅读法」为什么全是错的!?
    新手VS高手,高手是怎么读书的?
  • 原文地址:https://www.cnblogs.com/mamaxiaoling/p/8251816.html
Copyright © 2011-2022 走看看