2014-04-05 3 views
-1

모양을 이동하는 동안 문제가 있습니다. 선을 클릭하고 끌면 선이 2 줄로 표시됩니다. 문제는 내 마우스 이벤트 코드에있는 것 같습니다 내 마우스 이벤트 코드 :그리기 후 모양을 이동하는 방법

private void Form1_MouseDown(object sender, MouseEventArgs e) 
    { 
     if (e.Button == MouseButtons.Left) 
     { 
      if (obj.IsPointOnLine(e.Location, 5) == true) 
      { 
       this.Cursor = Cursors.SizeAll; 
       obj.isDragging = true; 
       deltaStart = new Point(obj.mstartpoint.X - e.Location.X, obj.mstartpoint.Y - e.Location.Y); 
       deltaEnd = new Point(obj.mendpoint.X - e.Location.X, obj.mendpoint.Y - e.Location.Y); 
      } 
      else if (obj.IsPointOnLine(e.Location, 5) == false) 
      { 
       this.Cursor = Cursors.Cross; 
       obj.mstartpoint = e.Location; 
      } 
     } 
    } 

    private void Form1_MouseMove(object sender, MouseEventArgs e) 
    { 
     if (obj.isDragging && deltaStart != null && deltaEnd != null) 
     { 
      obj.mstartpoint = new Point(deltaStart.X + e.Location.X, deltaStart.Y + e.Location.Y); 
      obj.mendpoint = new Point(deltaEnd.X + e.Location.X, deltaEnd.Y + e.Location.Y); 
      Refresh(); 
      Update(); 
     } 
     else if ((Control.ModifierKeys & Keys.Shift) != 0) 
     { 
      if ((Control.MouseButtons & MouseButtons.Left) != 0) 
      { 
       obj.mendpoint = e.Location; 
       switch (obj.mshape) 
       { 
        case 1: 
         obj.mshape = 3; 
         break; 
        case 2: 
         obj.mshape = 4; 
         break; 
       } 
       Invalidate(); 
      } 
     } 
     else if (e.Button == MouseButtons.Left) 
     { 
      obj.mendpoint = e.Location; 
      switch (obj.mshape) 
      { 
       case 3: 
        obj.mshape = 1; 
        break; 
       case 4: 
        obj.mshape = 2; 
        break; 
      } 
      Invalidate(); 
     }   
    } 

    private void Form1_MouseUp(object sender, MouseEventArgs e) 
    { 
     obj.isDragging = false; 
     this.Cursor = Cursors.Default; 
     MyObject a = new MyObject(obj.mstartpoint, obj.mendpoint, obj.mshape, obj.mwidth, obj.mcolor); 
     ds.Add(a); 
    } 

당신은 내 소스 코드를 다운로드받을 해달라고하는 경우 : https://www.dropbox.com/s/rdk88k4661zc3nj/WindowsFormsApplication19.rar 내 문제를 해결하시기 바랍니다 내 나쁜 영어 죄송합니다, 감사합니다.

답변

관련 문제