Core.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. 
  2. using System;
  3. using System.Globalization;
  4. namespace Dongke.WinForm.Controls.InvoiceLayout.DrawBarcode
  5. {
  6. /// <summary>
  7. /// 条码图片显示方式
  8. /// </summary>
  9. public enum BarcodeShowType
  10. {
  11. /// <summary>
  12. /// 原图
  13. /// </summary>
  14. Original = 0,
  15. /// <summary>
  16. /// 居中显示
  17. /// </summary>
  18. Show,
  19. /// <summary>
  20. /// 缩放
  21. /// </summary>
  22. Zoom,
  23. }
  24. /// <summary>
  25. /// 条码打印余白
  26. /// </summary>
  27. [Serializable]
  28. public struct BarcodeMargin
  29. {
  30. private bool _all;
  31. private int _top;
  32. private int _left;
  33. private int _right;
  34. private int _bottom;
  35. /// <summary>
  36. /// 空
  37. /// </summary>
  38. public static readonly BarcodeMargin Empty = new BarcodeMargin(0);
  39. /// <summary>
  40. /// 相同值
  41. /// </summary>
  42. public int All
  43. {
  44. get
  45. {
  46. return (this._all ? this._top : -1);
  47. }
  48. set
  49. {
  50. if (value < 0)
  51. {
  52. return;
  53. }
  54. if (!this._all || this._top != value)
  55. {
  56. this._all = true;
  57. this._bottom = value;
  58. this._right = value;
  59. this._left = value;
  60. this._top = value;
  61. }
  62. }
  63. }
  64. /// <summary>
  65. /// 底边余白
  66. /// </summary>
  67. public int Bottom
  68. {
  69. get
  70. {
  71. //if (this._all)
  72. //{
  73. // return this._top;
  74. //}
  75. return this._bottom;
  76. }
  77. set
  78. {
  79. if (value < 0)
  80. {
  81. return;
  82. }
  83. if (this._bottom != value)
  84. {
  85. this._bottom = value;
  86. this.SetAll();
  87. }
  88. }
  89. }
  90. /// <summary>
  91. /// 左侧余白
  92. /// </summary>
  93. public int Left
  94. {
  95. get
  96. {
  97. //if (this._all)
  98. //{
  99. // return this._top;
  100. //}
  101. return this._left;
  102. }
  103. set
  104. {
  105. if (value < 0)
  106. {
  107. return;
  108. }
  109. if (this._left != value)
  110. {
  111. this._left = value;
  112. this.SetAll();
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// 右余白
  118. /// </summary>
  119. public int Right
  120. {
  121. get
  122. {
  123. //if (this._all)
  124. //{
  125. // return this._top;
  126. //}
  127. return this._right;
  128. }
  129. set
  130. {
  131. if (value < 0)
  132. {
  133. return;
  134. }
  135. if (this._right != value)
  136. {
  137. this._right = value;
  138. this.SetAll();
  139. }
  140. }
  141. }
  142. /// <summary>
  143. /// 顶边余白
  144. /// </summary>
  145. public int Top
  146. {
  147. get
  148. {
  149. return this._top;
  150. }
  151. set
  152. {
  153. if (value < 0)
  154. {
  155. return;
  156. }
  157. if (this._top != value)
  158. {
  159. this._top = value;
  160. this.SetAll();
  161. }
  162. }
  163. }
  164. /// <summary>
  165. /// 横向
  166. /// </summary>
  167. public int Horizontal
  168. {
  169. get
  170. {
  171. return this.Left + this.Right;
  172. }
  173. }
  174. /// <summary>
  175. /// 纵向
  176. /// </summary>
  177. public int Vertical
  178. {
  179. get
  180. {
  181. return this.Top + this.Bottom;
  182. }
  183. }
  184. /// <summary>
  185. /// 条码打印余白
  186. /// </summary>
  187. /// <param name="all"></param>
  188. public BarcodeMargin(int all)
  189. {
  190. //if (all < 0)
  191. //{
  192. // all = 0;
  193. //}
  194. this._all = true;
  195. this._bottom = all;
  196. this._right = all;
  197. this._left = all;
  198. this._top = all;
  199. }
  200. /// <summary>
  201. /// 条码打印余白
  202. /// </summary>
  203. /// <param name="left"></param>
  204. /// <param name="top"></param>
  205. /// <param name="right"></param>
  206. /// <param name="bottom"></param>
  207. public BarcodeMargin(int left, int top, int right, int bottom)
  208. {
  209. //if (left < 0)
  210. //{
  211. // left = 0;
  212. //}
  213. //if (top < 0)
  214. //{
  215. // top = 0;
  216. //}
  217. //if (right < 0)
  218. //{
  219. // right = 0;
  220. //}
  221. //if (bottom < 0)
  222. //{
  223. // bottom = 0;
  224. //}
  225. this._top = top;
  226. this._left = left;
  227. this._right = right;
  228. this._bottom = bottom;
  229. this._all = (this._top == this._left && this._top == this._right && this._top == this._bottom);
  230. }
  231. private void SetAll()
  232. {
  233. this._all = (this._top == this._left && this._top == this._right && this._top == this._bottom);
  234. }
  235. /// <summary>
  236. /// ToString
  237. /// </summary>
  238. /// <returns></returns>
  239. public override string ToString()
  240. {
  241. return string.Concat(new string[]
  242. {
  243. "Margin={Left=",
  244. this.Left.ToString(CultureInfo.CurrentCulture),
  245. ",Top=",
  246. this.Top.ToString(CultureInfo.CurrentCulture),
  247. ",Right=",
  248. this.Right.ToString(CultureInfo.CurrentCulture),
  249. ",Bottom=",
  250. this.Bottom.ToString(CultureInfo.CurrentCulture),
  251. "}"
  252. });
  253. }
  254. }
  255. }