CVisualFieldGDIObject.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. HoleNo = 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 Point GetOTSPos()
  24. {
  25. return new Point(OTSX, OTSY);
  26. }
  27. public override void OnPaint(PaintEventArgs e)
  28. {
  29. Color myColor = SelColor;
  30. System.Drawing.SolidBrush sampleBrush = new System.Drawing.SolidBrush(myColor);
  31. Pen pen;
  32. if (m_enable)
  33. {
  34. pen = new Pen(sampleBrush, 0.01f);
  35. }
  36. else
  37. {
  38. sampleBrush = new System.Drawing.SolidBrush(Color.Gray);
  39. pen = new Pen(new SolidBrush(Color.Gray), 0.01f);
  40. }
  41. e.Graphics.SmoothingMode = SmoothingMode.Default;
  42. //设置直线位置与尺寸
  43. PointF startPointF = new PointF(m_RegionF.Left, m_RegionF.Top);
  44. PointF endPointF = new PointF(m_RegionF.Right, m_RegionF.Bottom);
  45. if (m_RegionF.Height > 20)//won't display when it's too small,to speed up
  46. {
  47. float fontSize = m_RegionF.Width / 4;
  48. Font font;
  49. if (fontSize == 0)
  50. {
  51. font = new Font("宋体", 5, FontStyle.Regular);
  52. }
  53. else
  54. {
  55. font = new Font("宋体", fontSize, FontStyle.Regular);
  56. }
  57. StringFormat sf = new StringFormat();
  58. sf.Alignment = StringAlignment.Center;
  59. sf.LineAlignment = StringAlignment.Center;
  60. e.Graphics.DrawString(m_sequenceNum.ToString(), font, sampleBrush, m_RegionF, sf);
  61. }
  62. //绘制帧图
  63. e.Graphics.DrawRectangle(pen, startPointF.X, startPointF.Y, endPointF.X - startPointF.X, endPointF.Y - startPointF.Y);
  64. }
  65. }
  66. }