123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- namespace SmartCoalApplication.Core.CustomControl
- {
- /// <summary>
- /// 位置导航的圆形控件
- /// </summary>
- public partial class CircleControl : UserControl
- {
- /// <summary>
- /// 半径
- /// </summary>
- private int radius;
- private int smallRadius;
- private int location;
- public int position = 0;
- private Pen internalpen1 = new Pen(Color.Pink);
- private Pen internalpen2 = new Pen(Color.Pink);
- private Pen internalpen3 = new Pen(Color.Pink);
- private Pen internalpen4 = new Pen(Color.Pink);
- private Pen internalpen5 = new Pen(Color.Pink);
- private Pen internalpen6 = new Pen(Color.Pink);
- private Pen internalpen7 = new Pen(Color.Pink);
- private Pen internalpen8 = new Pen(Color.Pink);
- private Pen outpen1 = new Pen(Color.Black);
- private Pen outpen2 = new Pen(Color.Black);
- private Pen outpen3 = new Pen(Color.Black);
- private Pen outpen4 = new Pen(Color.Black);
- private Pen outpen5 = new Pen(Color.Black);
- private Pen outpen6 = new Pen(Color.Black);
- private Pen outpen7 = new Pen(Color.Black);
- private Pen outpen8 = new Pen(Color.Black);
- private GraphicsPath graphicsPath = new GraphicsPath();
- GraphicsPath internalLeft = new GraphicsPath();
- GraphicsPath internalLeftTop = new GraphicsPath();
- GraphicsPath internalTop = new GraphicsPath();
- GraphicsPath internalRightTop = new GraphicsPath();
- GraphicsPath internalRight = new GraphicsPath();
- GraphicsPath internalRightBottom = new GraphicsPath();
- GraphicsPath internalBottom = new GraphicsPath();
- GraphicsPath internalLeftBottom = new GraphicsPath();
- GraphicsPath outLeft = new GraphicsPath();
- GraphicsPath outLeftTop = new GraphicsPath();
- GraphicsPath outTop = new GraphicsPath();
- GraphicsPath outRightTop = new GraphicsPath();
- GraphicsPath outRight = new GraphicsPath();
- GraphicsPath outRightBottom = new GraphicsPath();
- GraphicsPath outBottom = new GraphicsPath();
- GraphicsPath outLeftBottom = new GraphicsPath();
- public CircleControl(int radius)
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
- InitializeComponent();
- this.Size = new Size(radius*2+2, radius*2+2);
- this.radius = radius;
- this.smallRadius = (radius - 10)/2;
- this.location = (radius * 2 - smallRadius * 2) / 2;
- this.Paint += new PaintEventHandler(this.Control_Paint);
- this.MouseMove += new MouseEventHandler(this.Control_Move);
- this.MouseLeave += new EventHandler(this.Control_Leave);
- this.MouseClick += new MouseEventHandler(this.Control_Click);
- this.MouseDown += new MouseEventHandler(this.Control_MouseDown);
- this.MouseUp += new MouseEventHandler(this.Control_MouseUp);
- //double d = smallRadius / Math.Tan(90.0-22.5);
- //double x = Math.Sqrt(Math.Pow(d,2) - Math.Pow(smallRadius, 2));
- //int x1 = (int)((smallRadius * 2 - x) / 2);
- double d = smallRadius * 2 * Math.Sin(22.5 * Math.PI / 180);
- double x1 = (smallRadius * 2 - d*2) / 2;
- float d1 = (float)d;
- float x2 = (float)x1;
- internalLeft.AddPie(location, location, smallRadius*2, smallRadius * 2, 157.5f, 45f);
- internalLeftTop.AddPie(location, location, smallRadius*2, smallRadius * 2, 202.5f, 45f);
- internalTop.AddPie(location, location, smallRadius * 2, smallRadius * 2, 247.5f, 45f);
- internalRightTop.AddPie(location, location, smallRadius * 2, smallRadius * 2, 292.5f, 45f);
- internalRight.AddPie(location, location, smallRadius * 2, smallRadius * 2, 337.5f, 45f);
- internalRightBottom.AddPie(location, location, smallRadius * 2, smallRadius * 2, 22.5f, 45f);
- internalBottom.AddPie(location, location, smallRadius * 2, smallRadius * 2, 67.5f, 45f);
- internalLeftBottom.AddPie(location, location, smallRadius * 2, smallRadius * 2, 112.5f, 45f);
- outLeft.AddPie(0, 0, radius*2, radius * 2, 157.5f, 45f);
- outLeftTop.AddPie(0, 0, radius * 2, radius * 2, 202.5f, 45f);
- outTop.AddPie(0, 0, radius * 2, radius * 2, 247.5f, 45f);
- outRightTop.AddPie(0, 0, radius * 2, radius * 2, 292.5f, 45f);
- outRight.AddPie(0, 0, radius * 2, radius * 2, 337.5f, 45f);
- outRightBottom.AddPie(0, 0, radius * 2, radius * 2, 22.5f, 45f);
- outBottom.AddPie(0, 0, radius * 2, radius * 2, 67.5f, 45f);
- outLeftBottom.AddPie(0, 0, radius * 2, radius * 2, 112.5f, 45f);
- graphicsPath.AddEllipse(0, 0, radius * 2, radius * 2);
- }
- public event EventHandler clicked;
- public event EventHandler mouseUp;
- public event EventHandler mouseDown;
- private void Control_MouseDown(object sender, MouseEventArgs e)
- {
- OutMouseUpOrDown(e);
- if (!graphicsPath.IsVisible(e.Location))
- {
- this.Refresh();
- this.position = 9;
- }
- else
- {
- if (mouseDown != null)
- {
- mouseDown(this, e);
- }
- Console.WriteLine(position.ToString());
- }
- }
- private void Control_MouseUp(object sender, MouseEventArgs e)
- {
- OutMouseUpOrDown(e);
- if (!graphicsPath.IsVisible(e.Location))
- {
- this.Refresh();
- this.position = 9;
- }
- else
- {
- if (mouseUp != null)
- {
- mouseUp(this, e);
- }
- Console.WriteLine(position.ToString());
- }
- }
- private void Control_Click(object sender, MouseEventArgs e)
- {
- InternalClickEvent(e);
- OutClickEvent(e);
- if (!graphicsPath.IsVisible(e.Location))
- {
- this.Refresh();
- this.position = 0;
- }
- else
- {
- if (clicked != null)
- {
- clicked(this, e);
- }
- Console.WriteLine(position.ToString());
- //MessageBox.Show("" + position);
- }
- }
- private void Control_Leave(object sender, EventArgs e)
- {
- InitPen();
- this.position = 0;
- }
- private void Control_Move(object sender, MouseEventArgs e)
- {
- InitPen();
- InternalMoveEvent(e);
- OutMoveEvent(e);
- if(!graphicsPath.IsVisible(e.Location))
- {
- InitPen();
- this.Refresh();
- }
- }
- private void Control_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- e.Graphics.DrawPath(outpen1, outLeft);
- e.Graphics.DrawPath(outpen2, outLeftTop);
- e.Graphics.DrawPath(outpen3, outTop);
- e.Graphics.DrawPath(outpen4, outRightTop);
- e.Graphics.DrawPath(outpen5, outRight);
- e.Graphics.DrawPath(outpen6, outRightBottom);
- e.Graphics.DrawPath(outpen7, outBottom);
- e.Graphics.DrawPath(outpen8, outLeftBottom);
- e.Graphics.DrawPath(internalpen1, internalLeft);
- e.Graphics.DrawPath(internalpen2, internalLeftTop);
- e.Graphics.DrawPath(internalpen3, internalTop);
- e.Graphics.DrawPath(internalpen4, internalRightTop);
- e.Graphics.DrawPath(internalpen5, internalRight);
- e.Graphics.DrawPath(internalpen6, internalRightBottom);
- e.Graphics.DrawPath(internalpen7, internalBottom);
- e.Graphics.DrawPath(internalpen8, internalLeftBottom);
-
- //e.Graphics.DrawEllipse(internalpen, 0, 0, radius*2, radius*2);
- //e.Graphics.DrawEllipse(internalpen, location, location, smallRadius*2, smallRadius*2);
-
- }
- private void InitPen()
- {
- internalpen1 = new Pen(Color.Pink);
- internalpen2 = new Pen(Color.Pink);
- internalpen3 = new Pen(Color.Pink);
- internalpen4 = new Pen(Color.Pink);
- internalpen5 = new Pen(Color.Pink);
- internalpen6 = new Pen(Color.Pink);
- internalpen7 = new Pen(Color.Pink);
- internalpen8 = new Pen(Color.Pink);
- outpen1 = new Pen(Color.Black);
- outpen2 = new Pen(Color.Black);
- outpen3 = new Pen(Color.Black);
- outpen4 = new Pen(Color.Black);
- outpen5 = new Pen(Color.Black);
- outpen6 = new Pen(Color.Black);
- outpen7 = new Pen(Color.Black);
- outpen8 = new Pen(Color.Black);
- }
- private void InternalMoveEvent(MouseEventArgs e)
- {
- if (internalLeft.IsVisible(e.Location))
- {
- internalpen1 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalLeftTop.IsVisible(e.Location))
- {
- internalpen2 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalTop.IsVisible(e.Location))
- {
- internalpen3 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalRightTop.IsVisible(e.Location))
- {
- internalpen4 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalRight.IsVisible(e.Location))
- {
- internalpen5 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalRightBottom.IsVisible(e.Location))
- {
- internalpen6 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalBottom.IsVisible(e.Location))
- {
- internalpen7 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- if (internalLeftBottom.IsVisible(e.Location))
- {
- internalpen8 = new Pen(Color.Blue);
- this.Refresh();
- return;
- }
- }
- private void OutMoveEvent(MouseEventArgs e)
- {
- if (outLeft.IsVisible(e.Location) && !internalLeft.IsVisible(e.Location))
- {
- outpen1 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outLeftTop.IsVisible(e.Location) && !internalLeftTop.IsVisible(e.Location))
- {
- outpen2 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outTop.IsVisible(e.Location) && !internalTop.IsVisible(e.Location))
- {
- outpen3 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outRightTop.IsVisible(e.Location) && !internalRightTop.IsVisible(e.Location))
- {
- outpen4 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outRight.IsVisible(e.Location) && !internalRight.IsVisible(e.Location))
- {
- outpen5 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outRightBottom.IsVisible(e.Location) && !internalRightBottom.IsVisible(e.Location))
- {
- outpen6 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outBottom.IsVisible(e.Location) && !internalBottom.IsVisible(e.Location))
- {
- outpen7 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- if (outLeftBottom.IsVisible(e.Location) && !internalLeftBottom.IsVisible(e.Location))
- {
- outpen8 = new Pen(Color.Red);
- this.Refresh();
- return;
- }
- }
- private void InternalClickEvent(MouseEventArgs e)
- {
- if (internalLeft.IsVisible(e.Location))
- {
- internalpen1 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 1;
- return;
- }
- if (internalLeftTop.IsVisible(e.Location))
- {
- internalpen2 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 2;
- return;
- }
- if (internalTop.IsVisible(e.Location))
- {
- internalpen3 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 3;
- return;
- }
- if (internalRightTop.IsVisible(e.Location))
- {
- internalpen4 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 4;
- return;
- }
- if (internalRight.IsVisible(e.Location))
- {
- internalpen5 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 5;
- return;
- }
- if (internalRightBottom.IsVisible(e.Location))
- {
- internalpen6 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 6;
- return;
- }
- if (internalBottom.IsVisible(e.Location))
- {
- internalpen7 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 7;
- return;
- }
- if (internalLeftBottom.IsVisible(e.Location))
- {
- internalpen8 = new Pen(Color.Blue);
- this.Refresh();
- this.position = 8;
- return;
- }
- }
- private void OutClickEvent(MouseEventArgs e)
- {
- if (outLeft.IsVisible(e.Location) && !internalLeft.IsVisible(e.Location))
- {
- outpen1 = new Pen(Color.Red);
- this.Refresh();
- this.position = 9;
- return;
- }
- if (outLeftTop.IsVisible(e.Location) && !internalLeftTop.IsVisible(e.Location))
- {
- outpen2 = new Pen(Color.Red);
- this.Refresh();
- this.position = 10;
- return;
- }
- if (outTop.IsVisible(e.Location) && !internalTop.IsVisible(e.Location))
- {
- outpen3 = new Pen(Color.Red);
- this.Refresh();
- this.position = 11;
- return;
- }
- if (outRightTop.IsVisible(e.Location) && !internalRightTop.IsVisible(e.Location))
- {
- outpen4 = new Pen(Color.Red);
- this.Refresh();
- this.position = 12;
- return;
- }
- if (outRight.IsVisible(e.Location) && !internalRight.IsVisible(e.Location))
- {
- outpen5 = new Pen(Color.Red);
- this.Refresh();
- this.position = 13;
- return;
- }
- if (outRightBottom.IsVisible(e.Location) && !internalRightBottom.IsVisible(e.Location))
- {
- outpen6 = new Pen(Color.Red);
- this.Refresh();
- this.position = 14;
- return;
- }
- if (outBottom.IsVisible(e.Location) && !internalBottom.IsVisible(e.Location))
- {
- outpen7 = new Pen(Color.Red);
- this.Refresh();
- this.position = 15;
- return;
- }
- if (outLeftBottom.IsVisible(e.Location) && !internalLeftBottom.IsVisible(e.Location))
- {
- outpen8 = new Pen(Color.Red);
- this.Refresh();
- this.position = 16;
- return;
- }
- }
- private void OutMouseUpOrDown(MouseEventArgs e)
- {
- if (outLeft.IsVisible(e.Location) && !internalLeft.IsVisible(e.Location))
- {
- outpen1 = new Pen(Color.Red);
- this.Refresh();
- this.position = 9;
- return;
- }
- if (outLeftTop.IsVisible(e.Location) && !internalLeftTop.IsVisible(e.Location))
- {
- outpen2 = new Pen(Color.Red);
- this.Refresh();
- this.position = 10;
- return;
- }
- if (outTop.IsVisible(e.Location) && !internalTop.IsVisible(e.Location))
- {
- outpen3 = new Pen(Color.Red);
- this.Refresh();
- this.position = 11;
- return;
- }
- if (outRightTop.IsVisible(e.Location) && !internalRightTop.IsVisible(e.Location))
- {
- outpen4 = new Pen(Color.Red);
- this.Refresh();
- this.position = 12;
- return;
- }
- if (outRight.IsVisible(e.Location) && !internalRight.IsVisible(e.Location))
- {
- outpen5 = new Pen(Color.Red);
- this.Refresh();
- this.position = 13;
- return;
- }
- if (outRightBottom.IsVisible(e.Location) && !internalRightBottom.IsVisible(e.Location))
- {
- outpen6 = new Pen(Color.Red);
- this.Refresh();
- this.position = 14;
- return;
- }
- if (outBottom.IsVisible(e.Location) && !internalBottom.IsVisible(e.Location))
- {
- outpen7 = new Pen(Color.Red);
- this.Refresh();
- this.position = 15;
- return;
- }
- if (outLeftBottom.IsVisible(e.Location) && !internalLeftBottom.IsVisible(e.Location))
- {
- outpen8 = new Pen(Color.Red);
- this.Refresh();
- this.position = 16;
- return;
- }
- }
- }
- }
|