zoukankan      html  css  js  c++  java
  • Winform 鼠标拖动窗体

    窗体移动
    private Point mouseOffset;
            
    private bool isMouseDown = false;

            
    private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                
    int yOffset, xOffset;
                
    if(e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    xOffset 
    = -e.X - SystemInformation.FrameBorderSize.Width;
                    yOffset 
    = -e.Y - SystemInformation.FrameBorderSize.Height;
                    mouseOffset 
    = new Point(xOffset, yOffset);
                    isMouseDown 
    = true;
                }
            }

            
    private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                
    if(e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    isMouseDown 
    = false;
                }
            }

            
    private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                
    if(isMouseDown)
                {
                    Point p 
    = Control.MousePosition;
                    p.Offset(mouseOffset.X, mouseOffset.Y);
                    Location 
    = p;
                }
            }
  • 相关阅读:
    English,The Da Vinci Code,Chapter 1-3
    Algorithm,Ds,Binary Indexed Trees,树状数组,二分索引树
    Algorithm,Acm,RMQ
    Algorithm,Number Theory,Prime
    Algorithm,Number Theory,GCD
    English,The Da Vinci Code
    Algorithm,LCA,Tarjan,深搜+并查集,最近公共祖先
    python,keyword arguments
    Qt,QObject
    python,build in functions
  • 原文地址:https://www.cnblogs.com/pato/p/1966716.html
Copyright © 2011-2022 走看看