CRingGDIObject.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
  10. {
  11. class CRingGDIObject: CRectangleGDIObject
  12. {
  13. private float ringWidth=10;//the distance between outline circle and inside circle.
  14. public float GetRingWidth()
  15. {
  16. return ringWidth*m_zoomNum;
  17. }
  18. public void SetRingWidth(float value)
  19. {
  20. ringWidth = value;
  21. }
  22. public CRingGDIObject(RectangleF rect, CreateRectangleType cType,string holename,string name, Color selColor)
  23. {
  24. m_OrigineRegionF = rect;
  25. SetInitRegionF(m_OrigineRegionF);
  26. CreateType = cType;
  27. sampleName = name;
  28. nameOrHoleName = holename;
  29. SelColor = selColor;
  30. ID = System.Guid.NewGuid().ToString();
  31. }
  32. public override void OnPaint(PaintEventArgs e)
  33. {
  34. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  35. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  36. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  37. e.Graphics.DrawEllipse(Pens.Red, m_RegionF);
  38. RectangleF insideRegine = new RectangleF();
  39. insideRegine.X = m_RegionF.X + GetRingWidth();
  40. insideRegine.Y = m_RegionF.Y + GetRingWidth();
  41. insideRegine.Width = m_RegionF.Width - GetRingWidth() * 2;
  42. insideRegine.Height = m_RegionF.Height - GetRingWidth() * 2;
  43. e.Graphics.DrawEllipse(Pens.Red, insideRegine);
  44. }
  45. private GraphicsPath GetInsideCirclePath()
  46. {
  47. RectangleF insideRegine = new RectangleF();
  48. insideRegine.X = m_OrigineRegionF.X + ringWidth;
  49. insideRegine.Y = m_OrigineRegionF.Y + ringWidth;
  50. insideRegine.Width = m_OrigineRegionF.Width - ringWidth * 2;
  51. insideRegine.Height = m_OrigineRegionF.Height - ringWidth * 2;
  52. GraphicsPath GPath = new GraphicsPath();
  53. GPath.AddEllipse(insideRegine);
  54. return GPath;
  55. }
  56. override public bool ifRectangleIntersect(CRectangleGDIObject otherUnZoomgdi)
  57. {
  58. var path = GetInsideCirclePath();//the inside circle is the blank area that there's no field rect.
  59. var vertexPoints = otherUnZoomgdi.GetVertexPoints();
  60. foreach (var p in vertexPoints)
  61. {
  62. if (!path.IsVisible(p))
  63. {
  64. return true;
  65. }
  66. }
  67. return false;
  68. }
  69. }
  70. }