using PaintDotNet.Annotation.Enum; using System.Drawing; using System.Windows.Forms; namespace PaintDotNet.Annotation.Measure { /// /// 测量->直线->直线 /// public class ToolMeasureLine : ToolMeasureObject { private static MeasureLine line; private static bool moved = false; public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point pointscroll = GetEventPointInArea(drawArea, e.Location); if (line == null) { line = new MeasureLine(drawArea, new Point(pointscroll.X, pointscroll.Y), new Point(pointscroll.X + 1, pointscroll.Y + 1)); line.ISurfaceBox = drawArea; AddNewObject(drawArea, line); } } else { line = null; if (!drawArea.ContinuousDrawingMeasure()) { drawArea.ActiveTool = DrawToolType.Pointer; } OnMouseNotLeftDown(drawArea,line); } } public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e) { if (line != null) { line.moved = true; moved = true; Point pointscroll = GetEventPointInArea(drawArea, e.Location); if (line!= null) { line.MoveHandleTo(pointscroll, 2); drawArea.Refresh(); drawArea.GraphicsList.Dirty = true; } } } public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e) { //1、鼠标抬起的时候,先判断位置是不是等于第一个点 //2、如果是第一个点,那就是点击,不是拖动 //3、如果不是第一个点,那就画线 try { if (e.Button == MouseButtons.Left) { Point pointscroll = GetEventPointInArea(drawArea, e.Location); if ((pointscroll.X == line.startPoint.X && pointscroll.Y == line.startPoint.Y)) { return; } line.endPoint = pointscroll; if (!moved) { if (line != null) { for (int i = 0; i < drawArea.GraphicsList.Count; i++) { if (drawArea.GraphicsList[i].drawToolType == line.drawToolType) { drawArea.GraphicsList.RemoveAt(i); break; } } } } moved = false; if (line != null) { line.pointChange = false; line.mouseUpPointChange = false; } line = null; if (!drawArea.ContinuousDrawingMeasure()) { drawArea.ActiveTool = DrawToolType.Pointer; } OnMouseUpTwo(drawArea, e); } } catch (System.Exception) { } } public static void OnMouseClick(ISurfaceBox drawArea, MouseEventArgs e) { } /// /// 鼠标左键双击 /// /// /// public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e) { var abc = "str"; } /// /// 删除按键 /// /// /// public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 删除划痕处理&污迹处理选择区域的痕迹 /// /// /// public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 清空全部时调用该方法,将可能未绘制完的对象清空 /// public static void beginWithNewObject() { line = null; } } }