GraphicsItem.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. 
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using Microsoft.VisualBasic.PowerPacks;
  6. namespace Dongke.WinForm.Controls.InvoiceLayout
  7. {
  8. /// <summary>
  9. /// 图形item
  10. /// </summary>
  11. [Serializable]
  12. public abstract class GraphicsItem : LayoutItem
  13. {
  14. #region 成员变量
  15. /// <summary>
  16. /// 背景填充色
  17. /// </summary>
  18. protected Color _fillColor = Color.Black;
  19. /// <summary>
  20. /// 背景透明
  21. /// </summary>
  22. protected bool _isTransparent = true;
  23. /// <summary>
  24. /// 边框色
  25. /// </summary>
  26. protected Color _lineColor = Color.Black;
  27. /// <summary>
  28. /// 边框宽 (mm単位)
  29. /// </summary>
  30. protected float _lineWidth = 0.1f;
  31. /// <summary>
  32. /// 边框宽 - 绘制用 (mm単位)
  33. /// </summary>
  34. protected float _lineWidthDraw = 0.1f;
  35. #endregion 成员变量
  36. #region 属性
  37. /// <summary>
  38. /// 获取或设置Item的边框颜色。
  39. /// </summary>
  40. public Color LineColor
  41. {
  42. get
  43. {
  44. return _lineColor;
  45. }
  46. set
  47. {
  48. if (!value.Equals(_lineColor))
  49. {
  50. _lineColor = value;
  51. SetShapeProperty(GetZoom());
  52. if (Owner != null)
  53. {
  54. Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
  55. }
  56. }
  57. }
  58. }
  59. /// <summary>
  60. /// 获取或设置Item的边框宽度。
  61. /// </summary>
  62. /// <remarks>
  63. /// 设置小于0时,不显示边框。
  64. /// </remarks>
  65. public float LineWidth
  66. {
  67. get
  68. {
  69. return _lineWidth;
  70. }
  71. set
  72. {
  73. if (value < 0)
  74. {
  75. return;
  76. }
  77. if (value != _lineWidth)
  78. {
  79. _lineWidth = value;
  80. float zoom = GetZoom();
  81. _lineWidthDraw = _lineWidth * zoom;
  82. SetShapeProperty(zoom);
  83. if (Owner != null)
  84. {
  85. Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
  86. }
  87. }
  88. }
  89. }
  90. /// <summary>
  91. /// 获取或设置Item的背景填充色。
  92. /// </summary>
  93. public Color FillColor
  94. {
  95. get
  96. {
  97. return _fillColor;
  98. }
  99. set
  100. {
  101. if (!value.Equals(_fillColor))
  102. {
  103. _fillColor = value;
  104. SetShapeProperty(GetZoom());
  105. if (Owner != null)
  106. {
  107. Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
  108. }
  109. }
  110. }
  111. }
  112. /// <summary>
  113. /// 获取或设置Item的背景是否透明。
  114. /// </summary>
  115. public bool Transparent
  116. {
  117. get
  118. {
  119. return _isTransparent;
  120. }
  121. set
  122. {
  123. if (value != _isTransparent)
  124. {
  125. _isTransparent = value;
  126. SetShapeProperty(GetZoom());
  127. if (Owner != null)
  128. {
  129. Owner.SetItemChangedArgs(this, ItemChangeType.Modified);
  130. }
  131. }
  132. }
  133. }
  134. #endregion 属性
  135. #region 构造函数
  136. /// <summary>
  137. /// 构造函数
  138. /// </summary>
  139. /// <param name="box">Layoutbox</param>
  140. /// <param name="itemType">item类别</param>
  141. internal GraphicsItem(LayoutBox box, ItemType itemType)
  142. : base(box, itemType)
  143. {
  144. _width = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_WIDTH;
  145. _height = LayoutConsts.SHAPE_ITEM_SIZE_DEFAULT_HEIGHT;
  146. }
  147. #endregion 构造函数
  148. #region 函数
  149. /// <summary>
  150. /// 显示Item属性设置画面
  151. /// </summary>
  152. /// <returns>
  153. /// DialogResult.OK:选中的Item有效,设置成功<br/>
  154. /// DialogResult.Cancel:选中的Item有效,取消设置<br/>
  155. /// DialogResult.None:LayoutBox不是编辑模式,或选中的Item不是一个
  156. /// </returns>
  157. protected override DialogResult ShowItemPropertyDialogInner()
  158. {
  159. using (GraphicsItemSetting itemPropertySetting = new GraphicsItemSetting())
  160. {
  161. itemPropertySetting.ShapeLocationX = Left;
  162. itemPropertySetting.ShapeLocationY = Top;
  163. itemPropertySetting.ShapeWidth = Width;
  164. itemPropertySetting.ShapeHeight = Height;
  165. itemPropertySetting.LineColor = LineColor;
  166. itemPropertySetting.FillColor = FillColor;
  167. itemPropertySetting.LineWidth = LineWidth;
  168. itemPropertySetting.Transparent = Transparent;
  169. DialogResult result = itemPropertySetting.ShowDialog();
  170. if (result == DialogResult.OK)
  171. {
  172. Left = itemPropertySetting.ShapeLocationX;
  173. Top = itemPropertySetting.ShapeLocationY;
  174. Width = itemPropertySetting.ShapeWidth;
  175. Height = itemPropertySetting.ShapeHeight;
  176. LineColor = itemPropertySetting.LineColor;
  177. FillColor = itemPropertySetting.FillColor;
  178. LineWidth = itemPropertySetting.LineWidth;
  179. Transparent = itemPropertySetting.Transparent;
  180. ResetItemFrame();
  181. SetDrawProperty();
  182. Owner.Dirty = true;
  183. }
  184. return result;
  185. }
  186. }
  187. /// <summary>
  188. /// 初始化Item图形属性
  189. /// </summary>
  190. internal override void SetShapeProperty(float zoom)
  191. {
  192. if (_shape != null)
  193. {
  194. if (_lineWidthDraw > 0)
  195. {
  196. _shape.BorderStyle = System.Drawing.Drawing2D.DashStyle.Solid;
  197. _shape.BorderColor = _lineColor;
  198. _shape.BorderWidth = LayoutCommon.MillimeterToPixel(_lineWidthDraw);
  199. }
  200. else
  201. {
  202. _shape.BorderStyle = System.Drawing.Drawing2D.DashStyle.Custom;
  203. _shape.BorderWidth = 1;
  204. }
  205. if (_simpleShape != null)
  206. {
  207. _simpleShape.FillStyle = (_isTransparent) ? FillStyle.Transparent : FillStyle.Solid;
  208. _simpleShape.FillColor = _fillColor;
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// 初始化Item绘制用属性
  214. /// </summary>
  215. internal override float SetDrawProperty()
  216. {
  217. float zoom = base.SetDrawProperty();
  218. _lineWidthDraw = _lineWidth * zoom;
  219. SetShapeProperty(zoom);
  220. return zoom;
  221. }
  222. #endregion 函数
  223. }
  224. }