SNCodeEnterTextBox.cs 2.5 KB

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