UCTextBoxEx.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCTextBoxEx.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.Drawing;
  20. using System.Data;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Windows.Forms;
  24. using System.Runtime.InteropServices;
  25. using System.Diagnostics;
  26. using System.Threading;
  27. namespace HZH_Controls.Controls
  28. {
  29. /// <summary>
  30. /// Class UCTextBoxEx.
  31. /// Implements the <see cref="HZH_Controls.Controls.UCControlBase" />
  32. /// </summary>
  33. /// <seealso cref="HZH_Controls.Controls.UCControlBase" />
  34. [DefaultEvent("TextChanged")]
  35. public partial class UCTextBoxEx : UCControlBase
  36. {
  37. /// <summary>
  38. /// The m is show clear BTN
  39. /// </summary>
  40. private bool m_isShowClearBtn = true;
  41. /// <summary>
  42. /// The m int selection start
  43. /// </summary>
  44. int m_intSelectionStart = 0;
  45. /// <summary>
  46. /// The m int selection length
  47. /// </summary>
  48. int m_intSelectionLength = 0;
  49. /// <summary>
  50. /// 功能描述:是否显示清理按钮
  51. /// 作  者:HZH
  52. /// 创建日期:2019-02-28 16:13:52
  53. /// </summary>
  54. /// <value><c>true</c> if this instance is show clear BTN; otherwise, <c>false</c>.</value>
  55. [Description("是否显示清理按钮"), Category("自定义")]
  56. public bool IsShowClearBtn
  57. {
  58. get { return m_isShowClearBtn; }
  59. set
  60. {
  61. m_isShowClearBtn = value;
  62. if (value)
  63. {
  64. btnClear.Visible = !(txtInput.Text == "\r\n") && !string.IsNullOrEmpty(txtInput.Text);
  65. }
  66. else
  67. {
  68. btnClear.Visible = false;
  69. }
  70. }
  71. }
  72. /// <summary>
  73. /// The m is show search BTN
  74. /// </summary>
  75. private bool m_isShowSearchBtn = false;
  76. /// <summary>
  77. /// 是否显示查询按钮
  78. /// </summary>
  79. /// <value><c>true</c> if this instance is show search BTN; otherwise, <c>false</c>.</value>
  80. [Description("是否显示查询按钮"), Category("自定义")]
  81. public bool IsShowSearchBtn
  82. {
  83. get { return m_isShowSearchBtn; }
  84. set
  85. {
  86. m_isShowSearchBtn = value;
  87. btnSearch.Visible = value;
  88. }
  89. }
  90. /// <summary>
  91. /// Gets or sets a value indicating whether this instance is show keyboard.
  92. /// </summary>
  93. /// <value><c>true</c> if this instance is show keyboard; otherwise, <c>false</c>.</value>
  94. [Description("是否显示键盘"), Category("自定义")]
  95. public bool IsShowKeyboard
  96. {
  97. get
  98. {
  99. return btnKeybord.Visible;
  100. }
  101. set
  102. {
  103. btnKeybord.Visible = value;
  104. }
  105. }
  106. /// <summary>
  107. /// 获取或设置控件显示的文字的字体。
  108. /// </summary>
  109. /// <value>The font.</value>
  110. /// <PermissionSet>
  111. /// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  112. /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  113. /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" />
  114. /// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
  115. /// </PermissionSet>
  116. [Description("字体"), Category("自定义")]
  117. public new Font Font
  118. {
  119. get
  120. {
  121. return this.txtInput.Font;
  122. }
  123. set
  124. {
  125. this.txtInput.Font = value;
  126. }
  127. }
  128. /// <summary>
  129. /// Gets or sets the type of the input.
  130. /// </summary>
  131. /// <value>The type of the input.</value>
  132. [Description("输入类型"), Category("自定义")]
  133. public TextInputType InputType
  134. {
  135. get { return txtInput.InputType; }
  136. set { txtInput.InputType = value; }
  137. }
  138. /// <summary>
  139. /// 水印文字
  140. /// </summary>
  141. /// <value>The prompt text.</value>
  142. [Description("水印文字"), Category("自定义")]
  143. public string PromptText
  144. {
  145. get
  146. {
  147. return this.txtInput.PromptText;
  148. }
  149. set
  150. {
  151. this.txtInput.PromptText = value;
  152. }
  153. }
  154. /// <summary>
  155. /// Gets or sets the prompt font.
  156. /// </summary>
  157. /// <value>The prompt font.</value>
  158. [Description("水印字体"), Category("自定义")]
  159. public Font PromptFont
  160. {
  161. get
  162. {
  163. return this.txtInput.PromptFont;
  164. }
  165. set
  166. {
  167. this.txtInput.PromptFont = value;
  168. }
  169. }
  170. /// <summary>
  171. /// Gets or sets the color of the prompt.
  172. /// </summary>
  173. /// <value>The color of the prompt.</value>
  174. [Description("水印颜色"), Category("自定义")]
  175. public Color PromptColor
  176. {
  177. get
  178. {
  179. return this.txtInput.PromptColor;
  180. }
  181. set
  182. {
  183. this.txtInput.PromptColor = value;
  184. }
  185. }
  186. /// <summary>
  187. /// 获取或设置一个值,该值指示当输入类型InputType=Regex时,使用的正则表达式。
  188. /// </summary>
  189. /// <value>The regex pattern.</value>
  190. [Description("获取或设置一个值,该值指示当输入类型InputType=Regex时,使用的正则表达式。")]
  191. public string RegexPattern
  192. {
  193. get
  194. {
  195. return this.txtInput.RegexPattern;
  196. }
  197. set
  198. {
  199. this.txtInput.RegexPattern = value;
  200. }
  201. }
  202. /// <summary>
  203. /// 当InputType为数字类型时,能输入的最大值
  204. /// </summary>
  205. /// <value>The maximum value.</value>
  206. [Description("当InputType为数字类型时,能输入的最大值。")]
  207. public decimal MaxValue
  208. {
  209. get
  210. {
  211. return this.txtInput.MaxValue;
  212. }
  213. set
  214. {
  215. this.txtInput.MaxValue = value;
  216. }
  217. }
  218. /// <summary>
  219. /// 当InputType为数字类型时,能输入的最小值
  220. /// </summary>
  221. /// <value>The minimum value.</value>
  222. [Description("当InputType为数字类型时,能输入的最小值。")]
  223. public decimal MinValue
  224. {
  225. get
  226. {
  227. return this.txtInput.MinValue;
  228. }
  229. set
  230. {
  231. this.txtInput.MinValue = value;
  232. }
  233. }
  234. /// <summary>
  235. /// 当InputType为数字类型时,能输入的最小值
  236. /// </summary>
  237. /// <value>The length of the decimal.</value>
  238. [Description("当InputType为数字类型时,小数位数。")]
  239. public int DecLength
  240. {
  241. get
  242. {
  243. return this.txtInput.DecLength;
  244. }
  245. set
  246. {
  247. this.txtInput.DecLength = value;
  248. }
  249. }
  250. /// <summary>
  251. /// The key board type
  252. /// </summary>
  253. private KeyBoardType keyBoardType = KeyBoardType.UCKeyBorderAll_EN;
  254. /// <summary>
  255. /// Gets or sets the type of the key board.
  256. /// </summary>
  257. /// <value>The type of the key board.</value>
  258. [Description("键盘打开样式"), Category("自定义")]
  259. public KeyBoardType KeyBoardType
  260. {
  261. get { return keyBoardType; }
  262. set { keyBoardType = value; }
  263. }
  264. /// <summary>
  265. /// Occurs when [search click].
  266. /// </summary>
  267. [Description("查询按钮点击事件"), Category("自定义")]
  268. public event EventHandler SearchClick;
  269. /// <summary>
  270. /// Occurs when [text changed].
  271. /// </summary>
  272. [Description("文本改变事件"), Category("自定义")]
  273. public new event EventHandler TextChanged;
  274. /// <summary>
  275. /// Occurs when [keyboard click].
  276. /// </summary>
  277. [Description("键盘按钮点击事件"), Category("自定义")]
  278. public event EventHandler KeyboardClick;
  279. /// <summary>
  280. /// Gets or sets the input text.
  281. /// </summary>
  282. /// <value>The input text.</value>
  283. [Description("文本"), Category("自定义")]
  284. public string InputText
  285. {
  286. get
  287. {
  288. return txtInput.Text;
  289. }
  290. set
  291. {
  292. txtInput.Text = value;
  293. }
  294. }
  295. /// <summary>
  296. /// The focus border color
  297. /// </summary>
  298. private Color focusBorderColor = Color.FromArgb(255, 77, 59);
  299. /// <summary>
  300. /// Gets or sets the color of the focus border.
  301. /// </summary>
  302. /// <value>The color of the focus border.</value>
  303. [Description("获取焦点时边框颜色,当IsFocusColor=true有效"), Category("自定义")]
  304. public Color FocusBorderColor
  305. {
  306. get { return focusBorderColor; }
  307. set { focusBorderColor = value; }
  308. }
  309. /// <summary>
  310. /// The is focus color
  311. /// </summary>
  312. private bool isFocusColor = true;
  313. /// <summary>
  314. /// Gets or sets a value indicating whether this instance is focus color.
  315. /// </summary>
  316. /// <value><c>true</c> if this instance is focus color; otherwise, <c>false</c>.</value>
  317. [Description("获取焦点是否变色"), Category("自定义")]
  318. public bool IsFocusColor
  319. {
  320. get { return isFocusColor; }
  321. set { isFocusColor = value; }
  322. }
  323. /// <summary>
  324. /// The fill color
  325. /// </summary>
  326. private Color _FillColor;
  327. /// <summary>
  328. /// 当使用边框时填充颜色,当值为背景色或透明色或空值则不填充
  329. /// </summary>
  330. /// <value>The color of the fill.</value>
  331. public new Color FillColor
  332. {
  333. get
  334. {
  335. return _FillColor;
  336. }
  337. set
  338. {
  339. _FillColor = value;
  340. base.FillColor = value;
  341. this.txtInput.BackColor = value;
  342. }
  343. }
  344. /// <summary>
  345. /// Initializes a new instance of the <see cref="UCTextBoxEx" /> class.
  346. /// </summary>
  347. public UCTextBoxEx()
  348. {
  349. InitializeComponent();
  350. txtInput.SizeChanged += UCTextBoxEx_SizeChanged;
  351. this.SizeChanged += UCTextBoxEx_SizeChanged;
  352. txtInput.GotFocus += (a, b) =>
  353. {
  354. if (isFocusColor)
  355. this.RectColor = focusBorderColor;
  356. };
  357. txtInput.LostFocus += (a, b) =>
  358. {
  359. if (isFocusColor)
  360. this.RectColor = Color.FromArgb(220, 220, 220);
  361. };
  362. }
  363. /// <summary>
  364. /// Handles the SizeChanged event of the UCTextBoxEx control.
  365. /// </summary>
  366. /// <param name="sender">The source of the event.</param>
  367. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  368. void UCTextBoxEx_SizeChanged(object sender, EventArgs e)
  369. {
  370. this.txtInput.Location = new Point(this.txtInput.Location.X, (this.Height - txtInput.Height) / 2);
  371. }
  372. /// <summary>
  373. /// Handles the TextChanged event of the txtInput control.
  374. /// </summary>
  375. /// <param name="sender">The source of the event.</param>
  376. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  377. private void txtInput_TextChanged(object sender, EventArgs e)
  378. {
  379. if (m_isShowClearBtn)
  380. {
  381. btnClear.Visible = !(txtInput.Text == "\r\n") && !string.IsNullOrEmpty(txtInput.Text);
  382. }
  383. if (TextChanged != null)
  384. {
  385. TextChanged(sender, e);
  386. }
  387. }
  388. /// <summary>
  389. /// Handles the MouseDown event of the btnClear control.
  390. /// </summary>
  391. /// <param name="sender">The source of the event.</param>
  392. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  393. private void btnClear_MouseDown(object sender, MouseEventArgs e)
  394. {
  395. txtInput.Clear();
  396. txtInput.Focus();
  397. }
  398. /// <summary>
  399. /// Handles the MouseDown event of the btnSearch control.
  400. /// </summary>
  401. /// <param name="sender">The source of the event.</param>
  402. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  403. private void btnSearch_MouseDown(object sender, MouseEventArgs e)
  404. {
  405. if (SearchClick != null)
  406. {
  407. SearchClick(sender, e);
  408. }
  409. }
  410. /// <summary>
  411. /// The m FRM anchor
  412. /// </summary>
  413. Forms.FrmAnchor m_frmAnchor;
  414. /// <summary>
  415. /// Handles the MouseDown event of the btnKeybord control.
  416. /// </summary>
  417. /// <param name="sender">The source of the event.</param>
  418. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  419. private void btnKeybord_MouseDown(object sender, MouseEventArgs e)
  420. {
  421. if (keyBoardType == HZH_Controls.Controls.KeyBoardType.Null)
  422. return;
  423. m_intSelectionStart = this.txtInput.SelectionStart;
  424. m_intSelectionLength = this.txtInput.SelectionLength;
  425. this.FindForm().ActiveControl = this;
  426. this.FindForm().ActiveControl = this.txtInput;
  427. switch (keyBoardType)
  428. {
  429. case KeyBoardType.UCKeyBorderAll_EN:
  430. if (m_frmAnchor == null)
  431. {
  432. if (m_frmAnchor == null)
  433. {
  434. UCKeyBorderAll key = new UCKeyBorderAll();
  435. key.CharType = KeyBorderCharType.CHAR;
  436. key.RetractClike += (a, b) =>
  437. {
  438. m_frmAnchor.Hide();
  439. };
  440. m_frmAnchor = new Forms.FrmAnchor(this, key);
  441. m_frmAnchor.VisibleChanged += (a, b) =>
  442. {
  443. if (m_frmAnchor.Visible)
  444. {
  445. this.txtInput.SelectionStart = m_intSelectionStart;
  446. this.txtInput.SelectionLength = m_intSelectionLength;
  447. }
  448. };
  449. }
  450. }
  451. break;
  452. case KeyBoardType.UCKeyBorderAll_Num:
  453. if (m_frmAnchor == null)
  454. {
  455. UCKeyBorderAll key = new UCKeyBorderAll();
  456. key.CharType = KeyBorderCharType.NUMBER;
  457. key.RetractClike += (a, b) =>
  458. {
  459. m_frmAnchor.Hide();
  460. };
  461. m_frmAnchor = new Forms.FrmAnchor(this, key);
  462. m_frmAnchor.VisibleChanged += (a, b) =>
  463. {
  464. if (m_frmAnchor.Visible)
  465. {
  466. this.txtInput.SelectionStart = m_intSelectionStart;
  467. this.txtInput.SelectionLength = m_intSelectionLength;
  468. }
  469. };
  470. }
  471. break;
  472. case KeyBoardType.UCKeyBorderNum:
  473. if (m_frmAnchor == null)
  474. {
  475. UCKeyBorderNum key = new UCKeyBorderNum();
  476. m_frmAnchor = new Forms.FrmAnchor(this, key);
  477. m_frmAnchor.VisibleChanged += (a, b) =>
  478. {
  479. if (m_frmAnchor.Visible)
  480. {
  481. this.txtInput.SelectionStart = m_intSelectionStart;
  482. this.txtInput.SelectionLength = m_intSelectionLength;
  483. }
  484. };
  485. }
  486. break;
  487. case HZH_Controls.Controls.KeyBoardType.UCKeyBorderHand:
  488. m_frmAnchor = new Forms.FrmAnchor(this, new Size(504, 361));
  489. m_frmAnchor.VisibleChanged += m_frmAnchor_VisibleChanged;
  490. m_frmAnchor.Disposed += m_frmAnchor_Disposed;
  491. Panel p = new Panel();
  492. p.Dock = DockStyle.Fill;
  493. p.Name = "keyborder";
  494. m_frmAnchor.Controls.Add(p);
  495. UCBtnExt btnDelete = new UCBtnExt();
  496. btnDelete.Name = "btnDelete";
  497. btnDelete.Size = new Size(80, 28);
  498. btnDelete.FillColor = Color.White;
  499. btnDelete.IsRadius = false;
  500. btnDelete.ConerRadius = 1;
  501. btnDelete.IsShowRect = true;
  502. btnDelete.RectColor = Color.FromArgb(189, 197, 203);
  503. btnDelete.Location = new Point(198, 332);
  504. btnDelete.BtnFont = new System.Drawing.Font("微软雅黑", 8);
  505. btnDelete.BtnText = "删除";
  506. btnDelete.BtnClick += (a, b) =>
  507. {
  508. SendKeys.Send("{BACKSPACE}");
  509. };
  510. m_frmAnchor.Controls.Add(btnDelete);
  511. btnDelete.BringToFront();
  512. UCBtnExt btnEnter = new UCBtnExt();
  513. btnEnter.Name = "btnEnter";
  514. btnEnter.Size = new Size(82, 28);
  515. btnEnter.FillColor = Color.White;
  516. btnEnter.IsRadius = false;
  517. btnEnter.ConerRadius = 1;
  518. btnEnter.IsShowRect = true;
  519. btnEnter.RectColor = Color.FromArgb(189, 197, 203);
  520. btnEnter.Location = new Point(278, 332);
  521. btnEnter.BtnFont = new System.Drawing.Font("微软雅黑", 8);
  522. btnEnter.BtnText = "确定";
  523. btnEnter.BtnClick += (a, b) =>
  524. {
  525. SendKeys.Send("{ENTER}");
  526. m_frmAnchor.Hide();
  527. };
  528. m_frmAnchor.Controls.Add(btnEnter);
  529. btnEnter.BringToFront();
  530. m_frmAnchor.VisibleChanged += (a, b) =>
  531. {
  532. if (m_frmAnchor.Visible)
  533. {
  534. this.txtInput.SelectionStart = m_intSelectionStart;
  535. this.txtInput.SelectionLength = m_intSelectionLength;
  536. }
  537. };
  538. break;
  539. }
  540. if (!m_frmAnchor.Visible)
  541. m_frmAnchor.Show(this.FindForm());
  542. if (KeyboardClick != null)
  543. {
  544. KeyboardClick(sender, e);
  545. }
  546. }
  547. /// <summary>
  548. /// Handles the Disposed event of the m_frmAnchor control.
  549. /// </summary>
  550. /// <param name="sender">The source of the event.</param>
  551. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  552. void m_frmAnchor_Disposed(object sender, EventArgs e)
  553. {
  554. if (m_HandAppWin != IntPtr.Zero)
  555. {
  556. if (m_HandPWin != null && !m_HandPWin.HasExited)
  557. m_HandPWin.Kill();
  558. m_HandPWin = null;
  559. m_HandAppWin = IntPtr.Zero;
  560. }
  561. }
  562. /// <summary>
  563. /// The m hand application win
  564. /// </summary>
  565. IntPtr m_HandAppWin;
  566. /// <summary>
  567. /// The m hand p win
  568. /// </summary>
  569. Process m_HandPWin = null;
  570. /// <summary>
  571. /// The m hand executable name
  572. /// </summary>
  573. string m_HandExeName = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "HandInput\\handinput.exe");
  574. /// <summary>
  575. /// Handles the VisibleChanged event of the m_frmAnchor control.
  576. /// </summary>
  577. /// <param name="sender">The source of the event.</param>
  578. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  579. void m_frmAnchor_VisibleChanged(object sender, EventArgs e)
  580. {
  581. if (m_frmAnchor.Visible)
  582. {
  583. var lstP = Process.GetProcessesByName("handinput");
  584. if (lstP.Length > 0)
  585. {
  586. foreach (var item in lstP)
  587. {
  588. item.Kill();
  589. }
  590. }
  591. m_HandAppWin = IntPtr.Zero;
  592. if (m_HandPWin == null)
  593. {
  594. m_HandPWin = null;
  595. m_HandPWin = System.Diagnostics.Process.Start(this.m_HandExeName);
  596. m_HandPWin.WaitForInputIdle();
  597. }
  598. while (m_HandPWin.MainWindowHandle == IntPtr.Zero)
  599. {
  600. Thread.Sleep(10);
  601. }
  602. m_HandAppWin = m_HandPWin.MainWindowHandle;
  603. Control p = m_frmAnchor.Controls.Find("keyborder", false)[0];
  604. SetParent(m_HandAppWin, p.Handle);
  605. ControlHelper.SetForegroundWindow(this.FindForm().Handle);
  606. MoveWindow(m_HandAppWin, -111, -41, 626, 412, true);
  607. }
  608. else
  609. {
  610. if (m_HandAppWin != IntPtr.Zero)
  611. {
  612. if (m_HandPWin != null && !m_HandPWin.HasExited)
  613. m_HandPWin.Kill();
  614. m_HandPWin = null;
  615. m_HandAppWin = IntPtr.Zero;
  616. }
  617. }
  618. }
  619. /// <summary>
  620. /// Handles the MouseDown event of the UCTextBoxEx control.
  621. /// </summary>
  622. /// <param name="sender">The source of the event.</param>
  623. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  624. private void UCTextBoxEx_MouseDown(object sender, MouseEventArgs e)
  625. {
  626. this.ActiveControl = txtInput;
  627. }
  628. /// <summary>
  629. /// Handles the Load event of the UCTextBoxEx control.
  630. /// </summary>
  631. /// <param name="sender">The source of the event.</param>
  632. /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
  633. private void UCTextBoxEx_Load(object sender, EventArgs e)
  634. {
  635. if (!Enabled)
  636. {
  637. base.FillColor = Color.FromArgb(240, 240, 240);
  638. txtInput.BackColor = Color.FromArgb(240, 240, 240);
  639. }
  640. else
  641. {
  642. FillColor = _FillColor;
  643. txtInput.BackColor = _FillColor;
  644. }
  645. }
  646. /// <summary>
  647. /// Sets the parent.
  648. /// </summary>
  649. /// <param name="hWndChild">The h WND child.</param>
  650. /// <param name="hWndNewParent">The h WND new parent.</param>
  651. /// <returns>System.Int64.</returns>
  652. [DllImport("user32.dll", SetLastError = true)]
  653. private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
  654. /// <summary>
  655. /// Moves the window.
  656. /// </summary>
  657. /// <param name="hwnd">The HWND.</param>
  658. /// <param name="x">The x.</param>
  659. /// <param name="y">The y.</param>
  660. /// <param name="cx">The cx.</param>
  661. /// <param name="cy">The cy.</param>
  662. /// <param name="repaint">if set to <c>true</c> [repaint].</param>
  663. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  664. [DllImport("user32.dll", SetLastError = true)]
  665. private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
  666. /// <summary>
  667. /// Shows the window.
  668. /// </summary>
  669. /// <param name="hwnd">The HWND.</param>
  670. /// <param name="nCmdShow">The n command show.</param>
  671. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  672. [DllImport("user32.dll", EntryPoint = "ShowWindow")]
  673. private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
  674. /// <summary>
  675. /// Sets the window position.
  676. /// </summary>
  677. /// <param name="hWnd">The h WND.</param>
  678. /// <param name="hWndlnsertAfter">The h wndlnsert after.</param>
  679. /// <param name="X">The x.</param>
  680. /// <param name="Y">The y.</param>
  681. /// <param name="cx">The cx.</param>
  682. /// <param name="cy">The cy.</param>
  683. /// <param name="Flags">The flags.</param>
  684. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
  685. [DllImport("user32.dll")]
  686. private static extern bool SetWindowPos(IntPtr hWnd, int hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags);
  687. /// <summary>
  688. /// The GWL style
  689. /// </summary>
  690. private const int GWL_STYLE = -16;
  691. /// <summary>
  692. /// The ws child
  693. /// </summary>
  694. private const int WS_CHILD = 0x40000000;//设置窗口属性为child
  695. /// <summary>
  696. /// Gets the window long.
  697. /// </summary>
  698. /// <param name="hwnd">The HWND.</param>
  699. /// <param name="nIndex">Index of the n.</param>
  700. /// <returns>System.Int32.</returns>
  701. [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
  702. public static extern int GetWindowLong(IntPtr hwnd, int nIndex);
  703. /// <summary>
  704. /// Sets the window long.
  705. /// </summary>
  706. /// <param name="hwnd">The HWND.</param>
  707. /// <param name="nIndex">Index of the n.</param>
  708. /// <param name="dwNewLong">The dw new long.</param>
  709. /// <returns>System.Int32.</returns>
  710. [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
  711. public static extern int SetWindowLong(IntPtr hwnd, int nIndex, int dwNewLong);
  712. /// <summary>
  713. /// Sets the active window.
  714. /// </summary>
  715. /// <param name="handle">The handle.</param>
  716. /// <returns>IntPtr.</returns>
  717. [DllImport("user32.dll")]
  718. private extern static IntPtr SetActiveWindow(IntPtr handle);
  719. }
  720. }