GraphicsItemSetting.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. 
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace Dongke.WinForm.Controls.InvoiceLayout
  5. {
  6. internal partial class GraphicsItemSetting : Setting
  7. {
  8. #region 成员变量
  9. private bool _isTransparent = false; // 背景是否透明
  10. private Color _fillColor = Color.Black; // 背景颜色
  11. #endregion 成员变量
  12. #region 属性
  13. /// <summary>
  14. /// X(mm)
  15. /// </summary>
  16. public float ShapeLocationX
  17. {
  18. get
  19. {
  20. return System.Convert.ToSingle(numlocationX.Value);
  21. }
  22. set
  23. {
  24. decimal d = System.Convert.ToDecimal(value);
  25. if (d < numlocationX.Minimum)
  26. {
  27. d = numlocationX.Minimum;
  28. }
  29. else if (numlocationX.Maximum < d)
  30. {
  31. d = numlocationX.Maximum;
  32. }
  33. numlocationX.Value = d;
  34. }
  35. }
  36. /// <summary>
  37. /// Y(mm)
  38. /// </summary>
  39. public float ShapeLocationY
  40. {
  41. get
  42. {
  43. return System.Convert.ToSingle(numlocationY.Value);
  44. }
  45. set
  46. {
  47. decimal d = System.Convert.ToDecimal(value);
  48. if (d < numlocationY.Minimum)
  49. {
  50. d = numlocationY.Minimum;
  51. }
  52. else if (numlocationY.Maximum < d)
  53. {
  54. d = numlocationY.Maximum;
  55. }
  56. numlocationY.Value = d;
  57. }
  58. }
  59. /// <summary>
  60. /// 宽(mm)
  61. /// </summary>
  62. public float ShapeWidth
  63. {
  64. get
  65. {
  66. return System.Convert.ToSingle(numWidth.Value);
  67. }
  68. set
  69. {
  70. decimal d = System.Convert.ToDecimal(value);
  71. if (d < numWidth.Minimum)
  72. {
  73. d = numWidth.Minimum;
  74. }
  75. else if (numWidth.Maximum < d)
  76. {
  77. d = numWidth.Maximum;
  78. }
  79. numWidth.Value = d;
  80. }
  81. }
  82. /// <summary>
  83. /// 高(mm)
  84. /// </summary>
  85. public float ShapeHeight
  86. {
  87. get
  88. {
  89. return System.Convert.ToSingle(numHeight.Value);
  90. }
  91. set
  92. {
  93. decimal d = System.Convert.ToDecimal(value);
  94. if (d < numHeight.Minimum)
  95. {
  96. d = numHeight.Minimum;
  97. }
  98. else if (numHeight.Maximum < d)
  99. {
  100. d = numHeight.Maximum;
  101. }
  102. numHeight.Value = d;
  103. }
  104. }
  105. /// <summary>
  106. /// 线的颜色
  107. /// </summary>
  108. public Color LineColor
  109. {
  110. get
  111. {
  112. return lblLineColor.BackColor;
  113. }
  114. set
  115. {
  116. lblLineColor.BackColor = value;
  117. if (lblLineColor.BackColor != Color.White)
  118. {
  119. lblLineBColor.BackColor = lblLineColor.BackColor;
  120. }
  121. else
  122. {
  123. lblLineBColor.BackColor = Color.Black;
  124. }
  125. }
  126. }
  127. /// <summary>
  128. /// 背景颜色
  129. /// </summary>
  130. public Color FillColor
  131. {
  132. get
  133. {
  134. return _fillColor;
  135. }
  136. set
  137. {
  138. _fillColor = value;
  139. SetFillColor();
  140. }
  141. }
  142. /// <summary>
  143. /// 线宽
  144. /// </summary>
  145. public float LineWidth
  146. {
  147. get
  148. {
  149. return System.Convert.ToSingle(numLineWidth.Value);
  150. }
  151. set
  152. {
  153. decimal d = System.Convert.ToDecimal(value);
  154. if (d < numLineWidth.Minimum)
  155. {
  156. d = numLineWidth.Minimum;
  157. }
  158. else if (numLineWidth.Maximum < d)
  159. {
  160. d = numLineWidth.Maximum;
  161. }
  162. numLineWidth.Value = d;
  163. }
  164. }
  165. /// <summary>
  166. /// 背景是否透明
  167. /// </summary>
  168. public bool Transparent
  169. {
  170. get
  171. {
  172. return _isTransparent;
  173. }
  174. set
  175. {
  176. _isTransparent = value;
  177. SetFillColor();
  178. }
  179. }
  180. /// <summary>
  181. /// 线型图形
  182. /// </summary>
  183. public bool Line
  184. {
  185. get
  186. {
  187. return txtFillColor.Enabled;
  188. }
  189. set
  190. {
  191. txtFillColor.Enabled = !value;
  192. lblFillColor.Enabled = !value;
  193. lblFillBColor.Enabled = !value;
  194. btnSelectFillColor.Enabled = !value;
  195. btnFillTransparent.Enabled = !value;
  196. numWidth.Minimum = -999.9m;
  197. numHeight.Minimum = -999.9m;
  198. numHeight.Validating += new System.ComponentModel.CancelEventHandler(this.numHeight_Validating);
  199. numWidth.Validating += new System.ComponentModel.CancelEventHandler(this.numWidth_Validating);
  200. }
  201. }
  202. #endregion 属性
  203. #region 构造函数
  204. /// <summary>
  205. /// 构造函数
  206. /// </summary>
  207. public GraphicsItemSetting()
  208. {
  209. InitializeComponent();
  210. }
  211. #endregion 构造函数
  212. #region 函数
  213. /// <summary>
  214. /// 设置背景颜色
  215. /// </summary>
  216. private void SetFillColor()
  217. {
  218. if (_isTransparent)
  219. {
  220. lblFillColor.BackColor = Color.Empty;
  221. lblFillBColor.BackColor = Color.Empty;
  222. }
  223. else
  224. {
  225. lblFillColor.BackColor = _fillColor;
  226. if (_fillColor != Color.White)
  227. {
  228. lblFillBColor.BackColor = _fillColor;
  229. }
  230. else
  231. {
  232. lblFillBColor.BackColor = Color.Black;
  233. }
  234. }
  235. }
  236. #endregion 函数
  237. #region 事件处理
  238. /// <summary>
  239. /// 设置线的颜色
  240. /// </summary>
  241. /// <param name="sender">指定的对象</param>
  242. /// <param name="e">提供的事件数据</param>
  243. private void btnSelectLineColor_Click(object sender, System.EventArgs e)
  244. {
  245. colorDialog.Color = (lblLineColor.BackColor == Color.Transparent) ? Color.Empty : lblLineColor.BackColor;
  246. if (colorDialog.ShowDialog() == DialogResult.OK)
  247. {
  248. LineColor = colorDialog.Color;
  249. }
  250. }
  251. /// <summary>
  252. /// 设置背景颜色
  253. /// </summary>
  254. /// <param name="sender">指定的对象</param>
  255. /// <param name="e">提供的事件数据</param>
  256. private void btnSelectFillColor_Click(object sender, System.EventArgs e)
  257. {
  258. colorDialog.Color = _isTransparent ? Color.Empty : _fillColor;
  259. if (colorDialog.ShowDialog() == DialogResult.OK)
  260. {
  261. _fillColor = colorDialog.Color;
  262. Transparent = false;
  263. }
  264. }
  265. /// <summary>
  266. /// 设置线段是否透明
  267. /// </summary>
  268. /// <param name="sender">指定的对象</param>
  269. /// <param name="e">提供的事件数据</param>
  270. private void btnSelectLineTransparent_Click(object sender, System.EventArgs e)
  271. {
  272. lblLineColor.BackColor = Color.Transparent;
  273. lblLineBColor.BackColor = Color.Transparent;
  274. }
  275. /// <summary>
  276. /// 设置背景是否透明
  277. /// </summary>
  278. /// <param name="sender">指定的对象</param>
  279. /// <param name="e">提供的事件数据</param>
  280. private void btnFillTransparent_Click(object sender, System.EventArgs e)
  281. {
  282. Transparent = true;
  283. }
  284. /// <summary>
  285. /// 图形的宽度验证
  286. /// </summary>
  287. /// <param name="sender"></param>
  288. /// <param name="e"></param>
  289. private void numWidth_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  290. {
  291. if (numHeight.Value == 0 && numWidth.Value == 0)
  292. {
  293. numWidth.Value = 0.1m;
  294. }
  295. }
  296. /// <summary>
  297. /// 图形的高度验证
  298. /// </summary>
  299. /// <param name="sender"></param>
  300. /// <param name="e"></param>
  301. private void numHeight_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  302. {
  303. if (numHeight.Value == 0 && numWidth.Value == 0)
  304. {
  305. numHeight.Value = 0.1m;
  306. }
  307. }
  308. #endregion 事件处理
  309. }
  310. }