PageNumItemSetting.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. 
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace Dongke.WinForm.Controls.InvoiceLayout
  5. {
  6. internal partial class PageNumItemSetting : Setting
  7. {
  8. #region 成员变量
  9. private TextAlignment _textAlign = TextAlignment.LeftOrTop; // 文本对齐方式
  10. private TextAlignment _textAlignVertical = TextAlignment.LeftOrTop; // 文本垂直对齐方式
  11. private bool _isInit = true;
  12. #endregion
  13. #region 属性
  14. /// <summary>
  15. /// 文本字体
  16. /// </summary>
  17. public Font TextFont
  18. {
  19. get
  20. {
  21. return txtPreview.Font;
  22. }
  23. set
  24. {
  25. txtPreview.Font = value;
  26. }
  27. }
  28. /// <summary>
  29. /// 文本颜色
  30. /// </summary>
  31. public Color TextColor
  32. {
  33. get
  34. {
  35. return txtPreview.ForeColor;
  36. }
  37. set
  38. {
  39. txtPreview.ForeColor = value;
  40. }
  41. }
  42. /// <summary>
  43. /// 文本对齐方式
  44. /// </summary>
  45. public TextAlignment TextAlign
  46. {
  47. get
  48. {
  49. return _textAlign;
  50. }
  51. set
  52. {
  53. if (_textAlign != value)
  54. {
  55. _textAlign = value;
  56. }
  57. }
  58. }
  59. /// <summary>
  60. /// 文本垂直对齐方式
  61. /// </summary>
  62. public TextAlignment TextAlignVertical
  63. {
  64. get
  65. {
  66. return _textAlignVertical;
  67. }
  68. set
  69. {
  70. if (_textAlignVertical != value)
  71. {
  72. _textAlignVertical = value;
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// X
  78. /// </summary>
  79. public float TextLocationY
  80. {
  81. get
  82. {
  83. return System.Convert.ToSingle(numLoctionY.Value);
  84. }
  85. set
  86. {
  87. decimal d = System.Convert.ToDecimal(value);
  88. if (d < numLoctionY.Minimum)
  89. {
  90. d = numLoctionY.Minimum;
  91. }
  92. else if (numLoctionY.Maximum < d)
  93. {
  94. d = numLoctionY.Maximum;
  95. }
  96. numLoctionY.Value = d;
  97. }
  98. }
  99. /// <summary>
  100. /// Y
  101. /// </summary>
  102. public float TextLocationX
  103. {
  104. get
  105. {
  106. return System.Convert.ToSingle(numLoctionX.Value);
  107. }
  108. set
  109. {
  110. decimal d = System.Convert.ToDecimal(value);
  111. if (d < numLoctionX.Minimum)
  112. {
  113. d = numLoctionX.Minimum;
  114. }
  115. else if (numLoctionX.Maximum < d)
  116. {
  117. d = numLoctionX.Maximum;
  118. }
  119. numLoctionX.Value = d;
  120. }
  121. }
  122. /// <summary>
  123. /// 宽
  124. /// </summary>
  125. public float TextWidth
  126. {
  127. get
  128. {
  129. return System.Convert.ToSingle(numWidth.Value);
  130. }
  131. set
  132. {
  133. decimal d = System.Convert.ToDecimal(value);
  134. if (d < numWidth.Minimum)
  135. {
  136. d = numWidth.Minimum;
  137. }
  138. else if (numWidth.Maximum < d)
  139. {
  140. d = numWidth.Maximum;
  141. }
  142. numWidth.Value = d;
  143. }
  144. }
  145. /// <summary>
  146. /// 高
  147. /// </summary>
  148. public float TextHeight
  149. {
  150. get
  151. {
  152. return System.Convert.ToSingle(numHeight.Value);
  153. }
  154. set
  155. {
  156. decimal d = System.Convert.ToDecimal(value);
  157. if (d < numHeight.Minimum)
  158. {
  159. d = numHeight.Minimum;
  160. }
  161. else if (numHeight.Maximum < d)
  162. {
  163. d = numHeight.Maximum;
  164. }
  165. numHeight.Value = d;
  166. }
  167. }
  168. /// <summary>
  169. /// 文本格式
  170. /// </summary>
  171. public string TextFormat
  172. {
  173. get
  174. {
  175. return txtPageNumFormat.Text;
  176. }
  177. set
  178. {
  179. txtPageNumFormat.Text = value;
  180. if (string.IsNullOrEmpty(txtPageNumFormat.Text))
  181. {
  182. this.txtPreview.Text = "";
  183. }
  184. else
  185. {
  186. this.txtPreview.Text = txtPageNumFormat.Text.Replace("&[页码]", "1").Replace("&[总页数]", "1");
  187. }
  188. }
  189. }
  190. #endregion
  191. #region 构造函数
  192. /// <summary>
  193. /// 构造函数
  194. /// </summary>
  195. public PageNumItemSetting()
  196. {
  197. InitializeComponent();
  198. TextWidth = LayoutCommon.DefaultTextItemSizeWidth;
  199. TextHeight = LayoutCommon.DefaultTextItemSizeHeight;
  200. }
  201. #endregion
  202. #region 事件处理
  203. /// <summary>
  204. /// 文本设置
  205. /// </summary>
  206. /// <param name="sender">指定的对象</param>
  207. /// <param name="e">提供的事件数据</param>
  208. private void TextItemSetting_Shown(object sender, System.EventArgs e)
  209. {
  210. try
  211. {
  212. if (grbTextAlignment.Enabled)
  213. {
  214. switch (_textAlign)
  215. {
  216. case TextAlignment.LeftOrTop:
  217. rbtnLeft.Checked = true;
  218. txtPreview.TextAlign = HorizontalAlignment.Left;
  219. break;
  220. case TextAlignment.RightOrBottom:
  221. rbtnRight.Checked = true;
  222. txtPreview.TextAlign = HorizontalAlignment.Right;
  223. break;
  224. case TextAlignment.Center:
  225. rbtnCenter.Checked = true;
  226. txtPreview.TextAlign = HorizontalAlignment.Center;
  227. break;
  228. case TextAlignment.Evenness:
  229. rbtnEvenness.Checked = true;
  230. txtPreview.TextAlign = HorizontalAlignment.Left;
  231. break;
  232. }
  233. }
  234. if (grbTextAlignmentV.Enabled)
  235. {
  236. switch (_textAlignVertical)
  237. {
  238. case TextAlignment.LeftOrTop:
  239. rbtnTop.Checked = true;
  240. break;
  241. case TextAlignment.RightOrBottom:
  242. rbtnBottom.Checked = true;
  243. break;
  244. case TextAlignment.Center:
  245. rbtnCenterV.Checked = true;
  246. break;
  247. default:
  248. rbtnTop.Checked = true;
  249. break;
  250. }
  251. }
  252. }
  253. finally
  254. {
  255. _isInit = false;
  256. }
  257. }
  258. /// <summary>
  259. /// 设置文本颜色
  260. /// </summary>
  261. /// <param name="sender">指定的对象</param>
  262. /// <param name="e">提供的事件数据</param>
  263. private void btnSelectColor_Click(object sender, System.EventArgs e)
  264. {
  265. colorDialog.Color = txtPreview.ForeColor;
  266. if (colorDialog.ShowDialog() == DialogResult.OK)
  267. {
  268. txtPreview.ForeColor = colorDialog.Color;
  269. }
  270. }
  271. /// <summary>
  272. /// 设置文本对齐方式
  273. /// </summary>
  274. /// <param name="sender">指定的对象</param>
  275. /// <param name="e">提供的事件数据</param>
  276. private void rbtnTextAlignment_CheckedChanged(object sender, System.EventArgs e)
  277. {
  278. if (_isInit)
  279. {
  280. return;
  281. }
  282. if (rbtnLeft.Checked)
  283. {
  284. txtPreview.TextAlign = HorizontalAlignment.Left;
  285. _textAlign = TextAlignment.LeftOrTop;
  286. }
  287. else if (rbtnRight.Checked)
  288. {
  289. txtPreview.TextAlign = HorizontalAlignment.Right;
  290. _textAlign = TextAlignment.RightOrBottom;
  291. }
  292. else if (rbtnCenter.Checked)
  293. {
  294. txtPreview.TextAlign = HorizontalAlignment.Center;
  295. _textAlign = TextAlignment.Center;
  296. }
  297. else
  298. {
  299. txtPreview.TextAlign = HorizontalAlignment.Left;
  300. _textAlign = TextAlignment.Evenness;
  301. }
  302. if (rbtnTop.Checked)
  303. {
  304. _textAlignVertical = TextAlignment.LeftOrTop;
  305. }
  306. else if (rbtnBottom.Checked)
  307. {
  308. _textAlignVertical = TextAlignment.RightOrBottom;
  309. }
  310. else if (rbtnCenterV.Checked)
  311. {
  312. _textAlignVertical = TextAlignment.Center;
  313. }
  314. else
  315. {
  316. _textAlignVertical = TextAlignment.LeftOrTop;
  317. }
  318. }
  319. /// <summary>
  320. /// 设置文本字体。
  321. /// </summary>
  322. /// <param name="sender">指定的对象</param>
  323. /// <param name="e">提供的事件数据</param>
  324. private void btnFont_Click(object sender, System.EventArgs e)
  325. {
  326. fontDialog.Font = TextFont;
  327. if (fontDialog.ShowDialog() == DialogResult.OK)
  328. {
  329. TextFont = fontDialog.Font;
  330. }
  331. }
  332. /// <summary>
  333. /// 设置文本格式
  334. /// </summary>
  335. /// <param name="sender">指定的对象</param>
  336. /// <param name="e">提供的事件数据</param>
  337. private void txtPageNumFormat_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  338. {
  339. if (string.IsNullOrEmpty(txtPageNumFormat.Text))
  340. {
  341. this.txtPreview.Text = "";
  342. }
  343. else
  344. {
  345. this.txtPreview.Text = txtPageNumFormat.Text.Replace("&[页码]", "1").Replace("&[总页数]", "1");
  346. }
  347. }
  348. #endregion 事件处理
  349. }
  350. }