소리소문 없이... 사랑도 명예도 이름도 남김 없이...
DexCore.net

C#

Form 을 마우스로 Drag 하여 이동하기

탑~! 2011. 3. 22. 14:23

   20 private bool dragging;

   21         private Point downLocation;

   22 

   23         private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

   24         {

   25             if (e.Button == MouseButtons.Left)

   26             {

   27                 dragging = true;

   28                 downLocation = new Point(e.X, e.Y);

   29             }

   30         }

   31 

   32         private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

   33         {

   34             if (dragging)

   35             {

   36                 this.Location = new Point(this.Location.X + (e.X - downLocation.X),

   37                 this.Location.Y + (e.Y - downLocation.Y));

   38             }

   39         }

   40 

   41         private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)

   42         {

   43             if (e.Button == MouseButtons.Left)

   44             {

   45                 dragging = false;

   46             }

   47         }

728x90
반응형