TextBoxEx.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. namespace LYFZ.ComponentLibrary
  11. {
  12. public partial class TextBoxEx : OtherExpansion.SkinControl.SkinTextBox
  13. {
  14. #region 声明
  15. private bool _Isico = false;
  16. private Bitmap _Ico;
  17. private Padding _IcoPadding = new Padding(3, 3, 0, 0);
  18. #endregion
  19. public TextBoxEx()
  20. : base()
  21. {
  22. this.BaseText.TextChanged += BaseText_TextChanged;
  23. }
  24. #region 属性
  25. // [Obsolete("此属性过期不建议使用")]
  26. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  27. [Category("控件扩展属性"), Description("将控件设为密码显示")]
  28. public bool IsPass
  29. {
  30. get
  31. {
  32. return this.IsSystemPasswordChar; //BaseText.UseSystemPasswordChar;
  33. }
  34. set
  35. {
  36. this.IsSystemPasswordChar = value;
  37. // BaseText.UseSystemPasswordChar = value;
  38. // Invalidate(false);
  39. }
  40. }
  41. [Category("控件扩展属性"), Description("密码显示字符")]
  42. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  43. public char PassChar
  44. {
  45. get
  46. {
  47. return this.IsPasswordChat; //BaseText.PasswordChar;
  48. }
  49. set
  50. {
  51. this.IsPasswordChat = value;// BaseText.PasswordChar = value;
  52. Invalidate(false);
  53. }
  54. }
  55. Font _Font = new Font("宋体", 10.5f);
  56. // [Obsolete("此属性过期不建议使用")]
  57. [Category("控件扩展属性"), Description("此属性过期不建议使用 设置控件中文本字体")]
  58. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  59. public Font NewFont
  60. {
  61. get
  62. {
  63. return _Font;
  64. }
  65. set
  66. {
  67. _Font = value;
  68. }
  69. }
  70. // [Obsolete("此属性过期不建议使用")]
  71. [Category("控件扩展属性"), Description("此属性过期不建议使用 多行文本的编辑行")]
  72. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  73. public String[] lines
  74. {
  75. get
  76. {
  77. return this.Lines;
  78. }
  79. set
  80. {
  81. this.Lines = value;
  82. Invalidate(false);
  83. }
  84. }
  85. // [Obsolete("此属性过期不建议使用")]
  86. [Category("控件扩展属性"), Description("此属性过期不建议使用 是否显示图标")]
  87. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  88. public bool Isico
  89. {
  90. get
  91. {
  92. return _Isico;
  93. }
  94. set
  95. {
  96. _Isico = value;
  97. // this.Invalidate();
  98. }
  99. }
  100. // [Obsolete("此属性过期不建议使用")]
  101. [Category("控件扩展属性"), Description("此属性过期不建议使用 图标文件")]
  102. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  103. public Bitmap Ico
  104. {
  105. get
  106. {
  107. return _Ico;
  108. }
  109. set
  110. {
  111. _Ico = value; //Invalidate(false);
  112. }
  113. }
  114. // [Obsolete("此属性过期不建议使用")]
  115. [Category("控件扩展属性"), Description("此属性过期不建议使用 控件内部间距,图标文件")]
  116. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  117. public Padding IcoPadding
  118. {
  119. get { return _IcoPadding; }
  120. set
  121. {
  122. _IcoPadding = value;
  123. //this.Invalidate();
  124. }
  125. }
  126. #region 文本框边框颜色
  127. [DllImport("user32.dll")]
  128. private static extern IntPtr GetWindowDC(IntPtr hwnd);
  129. [DllImport("user32.dll")]
  130. private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
  131. private Color _borderColor = Color.Black;
  132. private int _borderWidth = 1;
  133. //
  134. // 摘要:
  135. // 获取或设置控件的边框颜色。
  136. //
  137. // 返回结果:
  138. // 控件的边框颜色 System.Drawing.Color。默认为 System.Drawing.Color.Black
  139. // 属性的值。
  140. // [Obsolete("此属性过期不建议使用")]
  141. [Description("组件的边框颜色。"), Category("此属性过期不建议使用 Appearance")]
  142. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  143. public Color BorderColor
  144. {
  145. get
  146. {
  147. return _borderColor;
  148. }
  149. set
  150. {
  151. _borderColor = value;
  152. this.Invalidate();
  153. }
  154. }
  155. //
  156. // 摘要:
  157. // 获取或设置控件的边框宽度。
  158. //
  159. // 返回结果:
  160. // 控件的边框宽度 int。默认为 1
  161. // 属性的值。
  162. // [Obsolete("此属性过期不建议使用")]
  163. [Description("组件的边框宽度。"), Category("此属性过期不建议使用 Appearance")]
  164. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  165. public int BorderWidth
  166. {
  167. get
  168. {
  169. return _borderWidth;
  170. }
  171. set
  172. {
  173. _borderWidth = value;
  174. // this.Invalidate();
  175. }
  176. }
  177. #endregion
  178. #endregion
  179. #region 方法
  180. //private bool _isCloseQaJiaoChar = true;
  181. ///// <summary>
  182. ///// 是否限制全角输入
  183. ///// </summary>
  184. //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(true)]
  185. //[Category("控件扩展属性"), Description("是否限制全角输入")]
  186. //public bool IsCloseQaJiaoChar
  187. //{
  188. // get { return _isCloseQaJiaoChar; }
  189. // set { _isCloseQaJiaoChar = value; }
  190. //}
  191. ///// <summary>
  192. ///// 重写输入限制
  193. ///// </summary>
  194. ///// <param name="e"></param>
  195. //protected override void OnKeyPress(KeyPressEventArgs e)
  196. //{
  197. // if (this.IsCloseQaJiaoChar && LYFZ.BLL.OtherCommonModel.IsQaJiaoChar(e.KeyChar))
  198. // { e.Handled = true; }
  199. // else
  200. // { base.OnKeyPress(e); }
  201. //}
  202. ///// <summary>
  203. ///// 重写离开事件
  204. ///// </summary>
  205. ///// <param name="e"></param>
  206. //protected override void OnLeave(EventArgs e)
  207. //{
  208. // if (this.IsCloseQaJiaoChar)
  209. // {
  210. // if (LYFZ.BLL.OtherCommonModel.StringContainsQaJiao(this.Text.Trim()))
  211. // { this.Text = ""; }
  212. // }
  213. // base.OnLeave(e);
  214. //}
  215. /// <summary>
  216. /// 定义delegate (定义文本框值更改后触发事件)
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. public delegate void TextBoxEx_TextChanged(object sender, EventArgs e);
  221. /// <summary>
  222. /// 用event 关键字声明事件对象
  223. /// </summary>
  224. [Category("控件扩展事件"), Description("文本框值修改时")]
  225. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  226. public event TextBoxEx_TextChanged EventTextBoxEx_TextChanged;
  227. /// <summary>
  228. ///
  229. /// </summary>
  230. /// <param name="sender"></param>
  231. /// <param name="e"></param>
  232. private void BaseText_TextChanged(object sender, EventArgs e)
  233. {
  234. if (this.EventTextBoxEx_TextChanged != null)
  235. EventTextBoxEx_TextChanged(sender, e);
  236. }
  237. #endregion
  238. }
  239. }