using PaintDotNet.Annotation.Enum; using System; using System.Drawing; using System.Windows.Forms; namespace PaintDotNet.Annotation.Label { /// /// 标注->工字线 /// public class ToolWorkType : ToolObject { private static DrawWorkType newWorkType; /// /// 辅助计算点击次数 /// private static int clickCount = 0; /// /// 数值输入 /// //private static NumericUpDown lab; private static LabelUsedDialog labelUsedDialog; private static ISurfaceBox areaNow; private static Cursor cursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur")); public static void OnMouseDown(ISurfaceBox drawArea, MouseEventArgs e) { areaNow = drawArea; if (e.Button == MouseButtons.Left) { clickCount += 1; Point p = GetEventPointInArea(drawArea, e.Location); if (clickCount == 1) { if (newWorkType == null) { newWorkType = new DrawWorkType(drawArea, p.X, p.Y); newWorkType.ISurfaceBox = drawArea; AddNewObject(drawArea, newWorkType); } } if (clickCount == 2) { Point temp = drawArea.GetCalcOriginPoint(); } if (clickCount == 3) { newWorkType.judgeP = GetEventPointInArea(drawArea, e.Location); labelUsedDialog = new LabelUsedDialog(); labelUsedDialog.Text = "工字线距离"; labelUsedDialog.textBox1.Text = newWorkType.labelWorkTypeStyleMode.distance.ToString(); labelUsedDialog.button1.Click += new EventHandler(LabelUsedDialogButton1_Click); labelUsedDialog.button2.Click += new EventHandler(LabelUsedDialogButton2_Click); labelUsedDialog.textBox1.KeyPress += new KeyPressEventHandler(TextBox1_KeyPress); labelUsedDialog.StartPosition = FormStartPosition.CenterParent; labelUsedDialog.ShowDialog(); //lab = new NumericUpDown(); //lab.Cursor = Cursors.Default; //lab.LostFocus += new EventHandler(OnNumbericLostFocus); ////lab.Location = new Point(p.X + temp.X ,p.Y + temp.Y); ////lab.Location = new Point(e.X, e.Y); //lab.Location = new Point(temp.X + (int)(p.X * drawArea.ScaleRatio) + 16, temp.Y + (int)(p.Y * drawArea.ScaleRatio) + 16); //lab.Maximum = 9999; //lab.Minimum = 0; //lab.DecimalPlaces = 2; //lab.Increment = 0.5M; //lab.Value = 10; //drawArea.Controls.Add(lab); //lab.Focus(); //lab.BringToFront(); //drawArea.Refresh(); } //if (clickCount == 3) //{ // newWorkType.textboxMessage = lab.Text; // drawArea.Controls.Remove(lab); // drawArea.Refresh(); // clickCount = 0; // newWorkType = null; // if (!drawArea.ContinuousDrawingLabel()) // { // OnMouseUpTwo(drawArea, e); // } //} } else { OnMouseNotLeftDown(drawArea, null); } } public static void OnMouseMove(ISurfaceBox drawArea, MouseEventArgs e) { if (newWorkType != null && clickCount == 1) { Point pointscroll = GetEventPointInArea(drawArea, e.Location); if (newWorkType.pointArray.Count == 1) newWorkType.setNextPoint(pointscroll); else newWorkType.pointArray[1] = pointscroll; drawArea.Refresh(); drawArea.GraphicsList.Dirty = true; } } private static void LabelUsedDialogButton1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(labelUsedDialog.textBox1.Text)) { MessageBox.Show("距离值不能为空,请重新输入"); return; } else { newWorkType.textboxMessage = labelUsedDialog.textBox1.Text; areaNow.Refresh(); clickCount = 0; newWorkType = null; if (!areaNow.ContinuousDrawingLabel()) { areaNow.ActiveTool = DrawToolType.Pointer; } OnMouseUpTwo(areaNow, null); labelUsedDialog.Close(); } } private static void LabelUsedDialogButton2_Click(object sender, EventArgs e) { if(newWorkType != null && areaNow != null) { RemoveOldObject(areaNow, newWorkType); areaNow.Refresh(); areaNow.RefreshLabelListDialog(); clickCount = 0; newWorkType = null; if (!areaNow.ContinuousDrawingLabel()) { OnMouseUpTwo(areaNow, null); } } } private static void TextBox1_KeyPress(object sender, KeyPressEventArgs e) { TextBox textBox1 = (TextBox)sender; //判断按键是不是要输入的类型 if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46) e.Handled = true; //小数点的处理 if ((int)e.KeyChar == 46)//小数点 { if (textBox1.Text.Length <= 0) e.Handled = true; //小数点不能在第一位 else { float f; float oldf; bool b1 = false, b2 = false; b1 = float.TryParse(textBox1.Text, out oldf); b2 = float.TryParse(textBox1.Text + e.KeyChar.ToString(), out f); if (b2 == false) { if (b1 == true) e.Handled = true; else e.Handled = false; } } } } //private static void OnNumbericLostFocus(object sender, EventArgs e) //{ // if (areaNow != null && lab != null) // { // if (!string.IsNullOrEmpty(lab.Text)) // newWorkType.textboxMessage = lab.Text; // else // RemoveOldObject(areaNow, newWorkType); // areaNow.Controls.Remove(lab); // areaNow.Refresh(); // clickCount = 0; // newWorkType = null; // if (!areaNow.ContinuousDrawingLabel()) // { // OnMouseUpTwo(areaNow, null); // } // } //} public static void OnMouseUp(ISurfaceBox drawArea, MouseEventArgs e) { } public static void OnMouseClick(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 鼠标左键双击 /// /// /// public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 删除按键 /// /// /// public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e) { } /// /// 删除划痕处理&污迹处理选择区域的痕迹 /// /// /// public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e) { } public static void beginWithNewObject() { } } }