| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- namespace SAGA.DotNetUtils.WinForms
- {
- public class InsertPointPictureBox : PictureBox
- {
- private int m_AllowMaxInsert;
- private Image m_Image = null;
- private int m_Index = -1;
- public InsertPointPictureBox()
- {
- this.AllowMaxInsert = 4;
- }
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (this.m_Image != null)
- {
- this.m_Image.Dispose();
- this.m_Image = null;
- }
- }
- public void FillInsertPoint(int intIndex)
- {
- if ((base.Image != null) && (this.m_Image == null))
- {
- this.m_Image = base.Image.Clone() as Image;
- }
- if (this.m_Image != null)
- {
- switch (this.AllowMaxInsert)
- {
- case 1:
- if (intIndex == 0)
- {
- break;
- }
- return;
- case 2:
- if (intIndex <= 1)
- {
- break;
- }
- return;
- case 3:
- if (intIndex <= 2)
- {
- break;
- }
- return;
- case 4:
- if (intIndex <= 3)
- {
- break;
- }
- return;
- }
- this.m_Index = intIndex;
- Image image = this.m_Image.Clone() as Image;
- if (base.Image != null)
- {
- base.Image.Dispose();
- }
- using (Graphics graphics = Graphics.FromImage(image))
- {
- int width = image.Width;
- int height = image.Height;
- int num3 = 8;
- Pen pen = new Pen(Color.Red, (float) num3);
- int num4 = (int) (Math.Min(width, height) * 0.15);
- switch (intIndex)
- {
- case 0:
- graphics.DrawEllipse(pen, 0, height - num4, num4, num4);
- break;
- case 1:
- graphics.DrawEllipse(pen, 0, 0, num4, num4);
- break;
- case 2:
- graphics.DrawEllipse(pen, width - num4, 0, num4, num4);
- break;
- case 3:
- graphics.DrawEllipse(pen, width - num4, height - num4, num4, num4);
- break;
- }
- graphics.Dispose();
- pen.Dispose();
- }
- base.Image = image;
- }
- }
- private double GetDistance(PointF pt1, PointF pt2)
- {
- double num = pt1.X - pt2.X;
- double num2 = pt1.Y - pt2.Y;
- return Math.Sqrt((num * num) + (num2 * num2));
- }
- private int GetNearPoint(PointF p, PointF[] points)
- {
- float maxValue = float.MaxValue;
- int num2 = 0;
- for (int i = 0; i < points.Length; i++)
- {
- float distance = (float) this.GetDistance(p, points[i]);
- if (distance < maxValue)
- {
- maxValue = distance;
- num2 = i;
- }
- }
- return num2;
- }
- protected override void OnMouseDoubleClick(MouseEventArgs e)
- {
- base.OnMouseDoubleClick(e);
- if (e.Button == MouseButtons.Left)
- {
- PointF[] points = new PointF[] { new PointF(0f, (float) base.Height), new PointF(0f, 0f), new PointF((float) base.Width, 0f), new PointF((float) base.Width, (float) base.Height) };
- int nearPoint = this.GetNearPoint((PointF) e.Location, points);
- this.FillInsertPoint(nearPoint);
- }
- }
- public int AllowMaxInsert
- {
- get
- {
- return this.m_AllowMaxInsert;
- }
- set
- {
- if (value > 4)
- {
- this.m_AllowMaxInsert = 4;
- }
- if (value < 1)
- {
- this.m_AllowMaxInsert = 1;
- }
- this.m_AllowMaxInsert = value;
- }
- }
- public int InsertIndex
- {
- get
- {
- return this.m_Index;
- }
- set
- {
- this.FillInsertPoint(value);
- }
- }
- public InsertLocations InsertLocation
- {
- get
- {
- switch (this.m_Index)
- {
- case 0:
- return InsertLocations.LeftBottom;
- case 1:
- return InsertLocations.LeftTop;
- case 2:
- return InsertLocations.RightTop;
- case 3:
- return InsertLocations.RightBottom;
- }
- return InsertLocations.LeftBottom;
- }
- }
- }
- }
|