DisplaySegment.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace OTSIncAReportGraph
  6. {
  7. /// <summary>
  8. /// 基本线类
  9. /// </summary>
  10. public class DisplaySegment : ICloneable
  11. {
  12. private RectangleF m_rect;
  13. private Color m_color;
  14. private float m_PenWidthAndHeight = 1;
  15. /// <summary>
  16. /// 克隆基本线
  17. /// </summary>
  18. /// <returns></returns>
  19. public object Clone()
  20. {
  21. var newSeg= new DisplaySegment();
  22. newSeg.m_rect = this.m_rect;
  23. newSeg.Color = this.Color;
  24. return newSeg;
  25. }
  26. public DisplaySegment()
  27. {
  28. }
  29. /// <summary>
  30. /// 画面的大小
  31. /// </summary>
  32. public RectangleF GetShowRect()
  33. { return m_rect; }
  34. /// <summary>
  35. /// 画面的大小
  36. /// </summary>
  37. public void SetShowRect(RectangleF value)
  38. { m_rect = value; }
  39. /// <summary>
  40. /// 线的颜色
  41. /// </summary>
  42. public Color Color
  43. {
  44. get { return m_color; }
  45. set { m_color = value; }
  46. }
  47. /// <summary>
  48. /// 绘制函数
  49. /// </summary>
  50. /// <param name="e"></param>
  51. public void OnPaint(PaintEventArgs e)
  52. {
  53. Pen p = new Pen(m_color, m_PenWidthAndHeight + 2f);//这里加1f的宽度后,用线组成多边形不会分散,效果正常,原因不知,但目前没有遇到问题
  54. e.Graphics.DrawLine(p, m_rect.X, m_rect.Y, m_rect.X + m_rect.Width, m_rect.Y);
  55. }
  56. }
  57. }