123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- using PaintDotNet.Annotation.Enum;
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Annotation.Label
- {
- /// <summary>
- /// 标注->工字线
- /// </summary>
- public class ToolWorkType : ToolObject
- {
- private static DrawWorkType newWorkType;
- /// <summary>
- /// 辅助计算点击次数
- /// </summary>
- private static int clickCount = 0;
- /// <summary>
- /// 数值输入
- /// </summary>
- //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)
- {
- }
- /// <summary>
- /// 鼠标左键双击
- /// </summary>
- /// <param name="drawArea"></param>
- /// <param name="e"></param>
- public static void OnMouseLeftDoubleClick(ISurfaceBox surfacebox, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 删除按键
- /// </summary>
- /// <param name="surfacebox"></param>
- /// <param name="e"></param>
- public static void OnDelKeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
- {
- }
- /// <summary>
- /// 删除划痕处理&污迹处理选择区域的痕迹
- /// </summary>
- /// <param name="surfacebox"></param>
- /// <param name="e"></param>
- public static void OnDel2KeyDown(ISurfaceBox surfacebox, MouseEventArgs e)
- {
- }
- public static void beginWithNewObject()
- {
- }
- }
- }
|