SNCodeEnterTextBox.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Windows.Forms;
  5. using UAS_MES_NEW.PublicMethod;
  6. namespace UAS_MES_NEW.CustomControl.TextBoxWithIcon
  7. {
  8. public partial class SNCodeEnterTextBox : TextBox
  9. {
  10. [DllImport("user32.dll", EntryPoint = "GetKeyboardState")]
  11. public static extern int GetKeyboardState(byte[] pbKeyState);
  12. public static bool CapsLockStatus
  13. {
  14. get
  15. {
  16. byte[] bs = new byte[256];
  17. GetKeyboardState(bs);
  18. return (bs[0x14] == 1);
  19. }
  20. }
  21. private string ID1;
  22. private string Power1;
  23. private string str;
  24. private string str1;
  25. private string str2;
  26. /// <summary>
  27. /// 设置锁定字段
  28. /// </summary>
  29. string AllPower1;
  30. public string AllPower
  31. {
  32. get { return AllPower1; }
  33. set { AllPower1 = value; }
  34. }
  35. public string ID
  36. {
  37. get { return ID1; }
  38. set { ID1 = value; }
  39. }
  40. public string Str
  41. {
  42. get { return str; }
  43. set { str = value; }
  44. }
  45. public string Str1
  46. {
  47. get { return str1; }
  48. set { str1 = value; }
  49. }
  50. public string Str2
  51. {
  52. get { return str2; }
  53. set { str2 = value; }
  54. }
  55. public string Power
  56. {
  57. get { return Power1; }
  58. set { Power1 = value; }
  59. }
  60. public SNCodeEnterTextBox()
  61. {
  62. InitializeComponent();
  63. }
  64. private void SNCodeEnterTextBox_Leave(object sender, EventArgs e)
  65. {
  66. this.BackColor = Color.White;
  67. }
  68. private void SNCodeEnterTextBox_Enter(object sender, EventArgs e)
  69. {
  70. this.BackColor = Color.GreenYellow;
  71. }
  72. private void SNCodeEnterTextBox_KeyDown(object sender, KeyEventArgs e)
  73. {
  74. if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.A)
  75. this.SelectAll();
  76. //不允许开启大写扫描
  77. if (e.KeyCode == Keys.Enter)
  78. {
  79. if (CapsLockStatus)
  80. {
  81. Text = "";
  82. BaseUtil.ShowError("请关闭大写锁定键[Caps Lock]");
  83. }
  84. }
  85. }
  86. }
  87. }