private void pictureBox_MouseMove(object sender, MouseEventArgs e) { isDrag = true; // 자유곡선 처리. 움직이는 좌표 받아와서 계속 라인 그려줌. if (e.Button == MouseButtons.Left && setShape.Equals("pen")) { // 불러오기 했을때 더블클릭시 선 그려짐 방지 if (isOpened) { isOpened = false; isDrag = false; return; } // 마우스 클릭한 상태에서 이동하는 실시간 좌표 값 저장 movePoint.X = e.X; movePoint.Y = e.Y; // 선 객체 생성 LineClass myPen = new LineClass(previousPoint, movePoint); myPen.setPen(currentPen); shapes_pen.AddLast(myPen); draw_pen(g, currentPen, previousPoint, movePoint); } }
private void pictureBox_MouseUp(object sender, MouseEventArgs e) { if (isDrag == true) { isChanged = true; g = pictureBox1.CreateGraphics(); // 현재 위치 받아옴 currentPoint = new Point(e.X, e.Y); // 그리기 모양 지정 if (setShape.Equals("circle")) { width = System.Math.Abs(currentPoint.X - previousPoint.X); height = System.Math.Abs(currentPoint.Y - previousPoint.Y); // 드래그하는 위치에 따라 도형의 시작 위치를 바꿔줌. if (previousPoint.X > currentPoint.X && previousPoint.Y > currentPoint.Y) { previousPoint = currentPoint; } else if (previousPoint.Y > currentPoint.Y) { previousPoint.Y = currentPoint.Y; } else if (previousPoint.X > currentPoint.X) { previousPoint.X = currentPoint.X; } // 원형 객체 생성 RectangleClass myCircle = new RectangleClass(previousPoint, currentPoint, width, height); myCircle.setPen(currentPen); shapes_cir.AddLast(myCircle); draw_circle(g, currentPen, previousPoint, currentPoint); } if (setShape.Equals("rectangle")) { width = System.Math.Abs(currentPoint.X - previousPoint.X); height = System.Math.Abs(currentPoint.Y - previousPoint.Y); // 드래그하는 위치에 따라 도형의 시작 위치를 바꿔줌. if (previousPoint.X > currentPoint.X && previousPoint.Y > currentPoint.Y) { previousPoint = currentPoint; } else if (previousPoint.Y > currentPoint.Y) { previousPoint.Y = currentPoint.Y; } else if (previousPoint.X > currentPoint.X) { previousPoint.X = currentPoint.X; } // 사각형 객체 생성 RectangleClass myRectangle = new RectangleClass(previousPoint, currentPoint, height, width); myRectangle.setPen(currentPen); shapes_rec.AddLast(myRectangle); draw_rectangle(g, currentPen, previousPoint, currentPoint); } if (setShape.Equals("line")) { // 선 객체 생성 LineClass myLine = new LineClass(previousPoint, currentPoint); myLine.setPen(currentPen); shapes_line.AddLast(myLine); draw_line(g, currentPen, previousPoint, currentPoint); } } isDrag = false; }