zoukankan      html  css  js  c++  java
  • 移动窗体

    在winform中可以拖动窗体移动!
     

    bool canMove = true;
    private Point mouseOffset; //记录鼠标指针的坐标
    private bool isMouseDown = false;

        #region 移动窗体
                 
            private void panel1_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 panel1_MouseMove(object sender, MouseEventArgs e)
            {
                if (canMove)
                {
                    if (isMouseDown)
                    {
                        Point mousePos = Control.MousePosition;
                        mousePos.Offset(mouseOffset.X, mouseOffset.Y);
                        Location = mousePos;
                    }
                }
            }
    
            private void panel1_MouseUp(object sender, MouseEventArgs e)
            {
                // 修改鼠标状态isMouseDown的值
                // 确保只有鼠标左键按下并移动时,才移动窗体
                if (e.Button == MouseButtons.Left)
                {
                    isMouseDown = false;
                }
            }
            #endregion
    View Code
  • 相关阅读:
    Javascript 进阶
    transform顺序浅谈
    js对象克隆
    js动画最佳实现——requestAnimationFrame
    svg标签
    typeof和instanceof
    js变量浅谈
    X-UA-compatible浅谈
    封装$
    面向对象
  • 原文地址:https://www.cnblogs.com/songxxu/p/3293248.html
Copyright © 2011-2022 走看看