會移動的panel

  • 2055
  • 0

會移動的panel

超好用的panel


public class PTarget : Panel
    {
  #region >>MouseMove<<
        private bool isMove = false;
        private Point MPoint = new Point(0, 0);
        private Point Oldpoint = new Point(0, 0);
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                isMove = true;
                MPoint = e.Location;
                Oldpoint = this.Location;
            }
            base.OnMouseDown(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (isMove)
            {
                this.Location = new Point(Oldpoint.X + e.X - MPoint.X, Oldpoint.Y + e.Y - MPoint.Y);
                Oldpoint = this.Location;
            }
            base.OnMouseMove(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            isMove = false;
            base.OnMouseUp(e);
        }
        #endregion
    }

 

===================

搞了C#

現在來學學維修筆電