UCKeyBorderNum.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 08-08-2019
  4. //
  5. // ***********************************************************************
  6. // <copyright file="UCKeyBorderNum.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. namespace HZH_Controls.Controls
  25. {
  26. /// <summary>
  27. /// Class UCKeyBorderNum.
  28. /// Implements the <see cref="System.Windows.Forms.UserControl" />
  29. /// </summary>
  30. /// <seealso cref="System.Windows.Forms.UserControl" />
  31. public partial class UCKeyBorderNum : UserControl
  32. {
  33. /// <summary>
  34. /// The use custom event
  35. /// </summary>
  36. private bool useCustomEvent = false;
  37. /// <summary>
  38. /// 是否使用自定义的事件来接收按键,当为true时将不再向系统发送按键请求
  39. /// </summary>
  40. /// <value><c>true</c> if [use custom event]; otherwise, <c>false</c>.</value>
  41. [Description("是否使用自定义的事件来接收按键,当为true时将不再向系统发送按键请求"), Category("自定义")]
  42. public bool UseCustomEvent
  43. {
  44. get { return useCustomEvent; }
  45. set { useCustomEvent = value; }
  46. }
  47. /// <summary>
  48. /// Occurs when [number click].
  49. /// </summary>
  50. [Description("数字点击事件"), Category("自定义")]
  51. public event EventHandler NumClick;
  52. /// <summary>
  53. /// Occurs when [backspace click].
  54. /// </summary>
  55. [Description("删除点击事件"), Category("自定义")]
  56. public event EventHandler BackspaceClick;
  57. /// <summary>
  58. /// Occurs when [enter click].
  59. /// </summary>
  60. [Description("回车点击事件"), Category("自定义")]
  61. public event EventHandler EnterClick;
  62. /// <summary>
  63. /// Initializes a new instance of the <see cref="UCKeyBorderNum" /> class.
  64. /// </summary>
  65. public UCKeyBorderNum()
  66. {
  67. InitializeComponent();
  68. }
  69. /// <summary>
  70. /// Handles the MouseDown event of the Num control.
  71. /// </summary>
  72. /// <param name="sender">The source of the event.</param>
  73. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  74. private void Num_MouseDown(object sender, MouseEventArgs e)
  75. {
  76. if (NumClick != null)
  77. {
  78. NumClick(sender, e);
  79. }
  80. if (useCustomEvent)
  81. return;
  82. Label lbl = sender as Label;
  83. SendKeys.Send(lbl.Tag.ToString());
  84. }
  85. /// <summary>
  86. /// Handles the MouseDown event of the Backspace control.
  87. /// </summary>
  88. /// <param name="sender">The source of the event.</param>
  89. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  90. private void Backspace_MouseDown(object sender, MouseEventArgs e)
  91. {
  92. if (BackspaceClick != null)
  93. {
  94. BackspaceClick(sender, e);
  95. }
  96. if (useCustomEvent)
  97. return;
  98. Label lbl = sender as Label;
  99. SendKeys.Send("{BACKSPACE}");
  100. }
  101. /// <summary>
  102. /// Handles the MouseDown event of the Enter control.
  103. /// </summary>
  104. /// <param name="sender">The source of the event.</param>
  105. /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param>
  106. private void Enter_MouseDown(object sender, MouseEventArgs e)
  107. {
  108. if (EnterClick != null)
  109. {
  110. EnterClick(sender, e);
  111. }
  112. if (useCustomEvent)
  113. return;
  114. SendKeys.Send("{ENTER}");
  115. }
  116. }
  117. }