FrmInputs.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="FrmInputs.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.ComponentModel;
  19. using System.Data;
  20. using System.Drawing;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. using HZH_Controls.Controls;
  25. namespace HZH_Controls.Forms
  26. {
  27. /// <summary>
  28. /// Class FrmInputs.
  29. /// Implements the <see cref="HZH_Controls.Forms.FrmWithOKCancel1" />
  30. /// </summary>
  31. /// <seealso cref="HZH_Controls.Forms.FrmWithOKCancel1" />
  32. public partial class FrmInputs : FrmWithOKCancel1
  33. {
  34. /// <summary>
  35. /// Gets the values.
  36. /// </summary>
  37. /// <value>The values.</value>
  38. public string[] Values { get; private set; }
  39. /// <summary>
  40. /// The m mast inputs
  41. /// </summary>
  42. private Dictionary<int, string> m_mastInputs = new Dictionary<int, string>();
  43. #region 构造函数
  44. /// <summary>
  45. /// 功能描述:构造函数
  46. /// 作  者:HZH
  47. /// 创建日期:2019-08-05 10:57:26
  48. /// 任务编号:POS
  49. /// </summary>
  50. /// <param name="strTitle">窗体标题</param>
  51. /// <param name="inPutLabels">The in put labels.</param>
  52. /// <param name="inTypes">输入项对应输入类型,key:输入项名称,如不设置默认不控制输入</param>
  53. /// <param name="regexs">输入项对应正则规则,当imTypes=Regex时有效,key:输入项名称,如不设置默认不控制输入</param>
  54. /// <param name="keyBoards">文本框键盘,key:输入项名称,如不设置默认英文键盘</param>
  55. /// <param name="mastInputs">必填输入项名称</param>
  56. /// <param name="defaultValues">输入项默认值,key:输入项名称</param>
  57. /// <exception cref="System.Exception">输入数量不能为空</exception>
  58. /// <exception cref="Exception">输入数量不能为空</exception>
  59. public FrmInputs(
  60. string strTitle,
  61. string[] inPutLabels,
  62. Dictionary<string, TextInputType> inTypes = null,
  63. Dictionary<string, string> regexs = null,
  64. Dictionary<string, HZH_Controls.Controls.KeyBoardType> keyBoards = null,
  65. List<string> mastInputs = null,
  66. Dictionary<string, string> defaultValues = null)
  67. {
  68. InitializeComponent();
  69. this.Title = strTitle;
  70. if (inPutLabels.Length <= 0)
  71. {
  72. throw new Exception("输入数量不能为空");
  73. }
  74. try
  75. {
  76. Values = new string[inPutLabels.Length];
  77. HZH_Controls.ControlHelper.FreezeControl(this, true);
  78. for (int i = inPutLabels.Length - 1; i >= 0; i--)
  79. {
  80. Panel p = new Panel();
  81. p.Dock = DockStyle.Top;
  82. p.Height = 62;
  83. p.Padding = new Padding(10);
  84. HZH_Controls.Controls.UCTextBoxEx txt = new Controls.UCTextBoxEx();
  85. txt.Dock = DockStyle.Fill;
  86. txt.IsShowKeyboard = true;
  87. txt.IsShowClearBtn = true;
  88. txt.Name = "txt_" + i;
  89. txt.TabIndex = i;
  90. if (inTypes != null && inTypes.ContainsKey(inPutLabels[i]))
  91. {
  92. txt.InputType = inTypes[inPutLabels[i]];
  93. if (txt.InputType == TextInputType.Regex && regexs != null && regexs.ContainsKey(inPutLabels[i]))
  94. txt.RegexPattern = regexs[inPutLabels[i]];
  95. }
  96. if (keyBoards != null && keyBoards.ContainsKey(inPutLabels[i]))
  97. txt.KeyBoardType = keyBoards[inPutLabels[i]];
  98. if (mastInputs != null && mastInputs.Contains(inPutLabels[i]))
  99. {
  100. m_mastInputs[i] = inPutLabels[i];
  101. }
  102. if (defaultValues != null && defaultValues.ContainsKey(inPutLabels[i]))
  103. txt.InputText = defaultValues[inPutLabels[i]];
  104. p.Controls.Add(txt);
  105. Label lbl = new Label();
  106. lbl.Text = inPutLabels[i];
  107. lbl.Padding = new System.Windows.Forms.Padding(0, 0, 5, 0);
  108. lbl.TextAlign = ContentAlignment.MiddleRight;
  109. lbl.AutoSize = false;
  110. lbl.Width = 120;
  111. lbl.Dock = DockStyle.Left;
  112. lbl.Font = new System.Drawing.Font("微软雅黑", 12);
  113. p.Controls.Add(lbl);
  114. Label lblT = new Label();
  115. if (mastInputs != null && mastInputs.Contains(inPutLabels[i]))
  116. {
  117. lblT.Text = "*";
  118. }
  119. else
  120. {
  121. lblT.Text = "";
  122. }
  123. lblT.AutoSize = false;
  124. lblT.TextAlign = ContentAlignment.MiddleLeft;
  125. lblT.Width = 25;
  126. lblT.Dock = DockStyle.Right;
  127. lblT.Font = new System.Drawing.Font("微软雅黑", 12);
  128. lblT.ForeColor = Color.Red;
  129. p.Controls.Add(lblT);
  130. this.panel3.Controls.Add(p);
  131. this.ActiveControl = txt;
  132. }
  133. this.Height = 124 + inPutLabels.Length * 62;
  134. }
  135. finally
  136. {
  137. HZH_Controls.ControlHelper.FreezeControl(this, false);
  138. }
  139. }
  140. #endregion
  141. /// <summary>
  142. /// Does the enter.
  143. /// </summary>
  144. protected override void DoEnter()
  145. {
  146. for (int i = 0; i < Values.Length; i++)
  147. {
  148. var cs = this.panel3.Controls.Find("txt_" + i, true);
  149. if (cs.Length > 0)
  150. {
  151. var txt = cs[0] as HZH_Controls.Controls.UCTextBoxEx;
  152. Values[i] = txt.InputText;
  153. if (m_mastInputs.ContainsKey(i) && string.IsNullOrWhiteSpace(txt.InputText))
  154. {
  155. HZH_Controls.Forms.FrmTips.ShowTipsInfo(this, "[" + m_mastInputs[i] + "]必须输入。");
  156. this.ActiveControl = txt.txtInput;
  157. return;
  158. }
  159. }
  160. }
  161. base.DoEnter();
  162. }
  163. }
  164. }