CVisualFieldGDIObject.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Windows.Forms;
  4. namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
  5. {
  6. public class CVisualFieldGDIObject : CDisplayGDIObject
  7. {
  8. private int m_sequenceNum;
  9. private bool m_enable;
  10. public CVisualFieldGDIObject(RectangleF rectField, int OTSx, int OTSy, string name, string sampleName, Color selColor)
  11. {
  12. m_OrigineRegionF = rectField;
  13. SetInitRegionF(m_OrigineRegionF);
  14. NameOrHoleName = name;
  15. SelColor = selColor;
  16. SampleName = sampleName;
  17. ID = System.Guid.NewGuid().ToString();
  18. OTSX = OTSx;
  19. OTSY = OTSy;
  20. }
  21. public int SequenceNum { get => m_sequenceNum; set => m_sequenceNum = value; }
  22. public bool Enable { get => m_enable; set => m_enable = value; }
  23. public override void OnPaint(PaintEventArgs e)
  24. {
  25. Color myColor = SelColor;
  26. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  27. Pen pen;
  28. if (m_enable)
  29. {
  30. pen = new Pen(sampleBrush, 0.01f);
  31. }
  32. else
  33. {
  34. pen = new Pen(new SolidBrush(Color.Gray), 0.01f);
  35. }
  36. e.Graphics.SmoothingMode = SmoothingMode.Default;
  37. //设置直线位置与尺寸
  38. PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
  39. PointF endPointF = new PointF(m_RegionF.Right, m_RegionF.Bottom);
  40. if (m_RegionF.Height > 20)//won't display when it's too small,to speed up
  41. {
  42. float fontSize = m_RegionF.Width / 4;
  43. Font font;
  44. if (fontSize == 0)
  45. {
  46. font = new Font("宋体", 5, FontStyle.Regular);
  47. }
  48. else
  49. {
  50. font = new Font("宋体", fontSize, FontStyle.Regular);
  51. }
  52. StringFormat sf = new StringFormat();
  53. sf.Alignment = StringAlignment.Center;
  54. sf.LineAlignment = StringAlignment.Center;
  55. e.Graphics.DrawString(m_sequenceNum.ToString(), font, sampleBrush, m_RegionF, sf);
  56. }
  57. //绘制帧图
  58. e.Graphics.DrawRectangle(pen, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
  59. }
  60. }
  61. }