zoukankan      html  css  js  c++  java
  • Winform 窗口拖动

    把窗口边框去掉后,窗口拖动问题:

     private Point mouseOffset; //记录鼠标指针的坐标 
            private bool isMouseDown = false; //记录鼠标按键是否按下 
    
            private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                int xOffset;
                int yOffset;
    
                if (e.Button == MouseButtons.Left)
                {
                    xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                    yOffset = -e.Y - SystemInformation.CaptionHeight -
                    SystemInformation.FrameBorderSize.Height;
                    mouseOffset = new Point(xOffset, yOffset);
                    isMouseDown = true;
                } 
            }
    
            private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                    Location = mousePos;
                } 
            }
    
            private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                // 修改鼠标状态isMouseDown的值 
                // 确保只有鼠标左键按下并移动时,才移动窗体 
                if (e.Button == MouseButtons.Left)
                {
                    isMouseDown = false;
                } 
            }
  • 相关阅读:
    swift 上的 lazy
    oc runtime
    iOS布局
    ios微信支付 v3
    好用的工具
    自己曾经没注意的东西
    根据文字计算出label的高度
    项目swift的一些问题
    UIAppearance
    书签
  • 原文地址:https://www.cnblogs.com/shadow-wolf/p/6136228.html
Copyright © 2011-2022 走看看