SNCodeEnterTextBox.cs 2.4 KB

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