UILine.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System.Drawing;
  2. using System.Drawing.Drawing2D;
  3. using System.Windows.Forms;
  4. using Microsoft.Drawing;
  5. namespace Microsoft.Windows.Forms
  6. {
  7. /// <summary>
  8. /// 虚拟直线控件
  9. /// </summary>
  10. public class UILine : UIControl
  11. {
  12. private bool m_Horizontal = true;
  13. /// <summary>
  14. /// 获取或设置是否水平线.true表示水平线,false表示垂直线
  15. /// </summary>
  16. public virtual bool Horizontal
  17. {
  18. get
  19. {
  20. return this.m_Horizontal;
  21. }
  22. set
  23. {
  24. if (value != this.m_Horizontal)
  25. {
  26. this.m_Horizontal = value;
  27. base.Invalidate();
  28. }
  29. }
  30. }
  31. private int m_LineWidth = 1;
  32. /// <summary>
  33. /// 获取或设置直线宽度
  34. /// </summary>
  35. public virtual int LineWidth
  36. {
  37. get
  38. {
  39. return this.m_LineWidth;
  40. }
  41. set
  42. {
  43. if (value != this.m_LineWidth)
  44. {
  45. this.m_LineWidth = value;
  46. this.Invalidate();
  47. }
  48. }
  49. }
  50. private Color m_LineColor = DefaultTheme.DarkDarkBorderColor;
  51. /// <summary>
  52. /// 获取或设置直线颜色
  53. /// </summary>
  54. public virtual Color LineColor
  55. {
  56. get
  57. {
  58. return this.m_LineColor;
  59. }
  60. set
  61. {
  62. if (value != this.m_LineColor)
  63. {
  64. this.m_LineColor = value;
  65. this.Invalidate();
  66. }
  67. }
  68. }
  69. private BlendStyle m_LineBlendStyle = BlendStyle.Solid;
  70. /// <summary>
  71. /// 渲染方式
  72. /// </summary>
  73. public virtual BlendStyle LineBlendStyle
  74. {
  75. get
  76. {
  77. return this.m_LineBlendStyle;
  78. }
  79. set
  80. {
  81. if (value != this.m_LineBlendStyle)
  82. {
  83. this.m_LineBlendStyle = value;
  84. base.Invalidate();
  85. }
  86. }
  87. }
  88. private DashStyle m_LineDashStyle = DashStyle.Solid;
  89. /// <summary>
  90. /// 获取或设置直线的虚线样式
  91. /// </summary>
  92. public virtual DashStyle LineDashStyle
  93. {
  94. get
  95. {
  96. return this.m_LineDashStyle;
  97. }
  98. set
  99. {
  100. if (value != this.m_LineDashStyle)
  101. {
  102. this.m_LineDashStyle = value;
  103. this.Invalidate();
  104. }
  105. }
  106. }
  107. /// <summary>
  108. /// 渲染控件
  109. /// </summary>
  110. /// <param name="e">数据</param>
  111. protected override void RenderSelf(PaintEventArgs e)
  112. {
  113. //准备
  114. Graphics g = e.Graphics;
  115. Rectangle rect = RectangleEx.Subtract(this.ClientRectangle, this.Padding);
  116. //计算起点终点
  117. Point begin, end;
  118. if (this.Horizontal)
  119. {
  120. begin = new Point(rect.X, (rect.Y + rect.Bottom) / 2);
  121. end = new Point(rect.Right, begin.Y);
  122. }
  123. else
  124. {
  125. begin = new Point((rect.X + rect.Right) / 2, rect.Y);
  126. end = new Point(begin.X, rect.Bottom);
  127. }
  128. //渲染
  129. this.Sprite.LineWidth = this.LineWidth;
  130. this.Sprite.LineColor = this.LineColor;
  131. this.Sprite.LineBlendStyle = this.LineBlendStyle;
  132. this.Sprite.LineDashStyle = this.LineDashStyle;
  133. base.Sprite.BeginRender(g);
  134. base.Sprite.RenderLine(begin, end);
  135. base.Sprite.EndRender();
  136. }
  137. }
  138. }