zoukankan      html  css  js  c++  java
  • winform窗体扁平化设置,窗体移动,关闭

    1,Winform窗体:设置扁平化

    2,窗体移动

    【2.1】主要代码:

            #region 窗体移动
    
            private Point mouseOff;//鼠标移动位置变量
            private bool leftFlag;//标签是否为左键
            private void Frm_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                    leftFlag = true;                  //点击左键按下时标注为true;
                }
            }
            private void Frm_MouseMove(object sender, MouseEventArgs e)
            {
                if (leftFlag)
                {
                    Point mouseSet = Control.MousePosition;
                    mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                    Location = mouseSet;
                }
            }
            private void Frm_MouseUp(object sender, MouseEventArgs e)
            {
                if (leftFlag)
                {
                    leftFlag = false;//释放鼠标后标注为false;
                }
            }
    
            #endregion
    

    【2.2】 窗体移动代码使用:把代码复制到这个位置

    【2.3】 绑定窗体移动代码

    注意:需要点击哪个控件移动,就绑定哪个控件的事件(我这里司绑定上面的Panel控件)

    3,其他的窗体移动代码

    【3.1】其他代码1:这个带需要绑定2个事件代码更简洁

            #region 窗体移动
    
            private Point mPoint;
    
            private void Frm_MouseDown(object sender, MouseEventArgs e)
            {
    
                mPoint = new Point(e.X, e.Y);
            }
    
            private void Frm_MouseMove(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    this.Location=new Point(this.Location.X+e.X-mPoint.X, this.Location.Y + e.Y - mPoint.Y);
                }
            }
    
            #endregion
    

     

    【3.2】其他代码2:调用windows的api实现无边框窗体移动,只用绑定一个事件

            #region 调用windows的api实现无边框窗体移动
    
    
            [DllImport("user32.dll")]
            public static extern bool ReleaseCapture();
    
            [DllImport("user32.dll")]
            public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
    
            public const int WM_SYSCOMMAND = 0x0112;
            public const int SC_MOVE = 0xF010;
            public const int HTCAPTION = 0x0002;
    
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
            }
    
    
            #endregion
    

    4,DataGridView扁平化设置

    https://i.cnblogs.com/posts/edit;postId=15688551

  • 相关阅读:
    don't run elasticsearch as root.
    详细讲解安全升级MySQL的方法
    mysql sql优化实例1(force index使用)
    mysql的force index
    【C++】string类用法
    【GAN】GAN设计与训练集锦
    【C++】VS Code配置
    【Windows】win10:硬件良好,软件系统出错
    【Windows】快速启动软件 非点击软件图标 无限弹窗
    【Ubuntu】利用sudo修改/etc/sudoers翻车
  • 原文地址:https://www.cnblogs.com/baozi789654/p/12735966.html
Copyright © 2011-2022 走看看