EnterTextBox.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace UAS_BARCODEIO
  5. {
  6. public partial class EnterTextBox : TextBox
  7. {
  8. //传值的备用字符串
  9. private string ID1;
  10. private string Power1;
  11. private string str;
  12. private string str1;
  13. private string str2;
  14. /// <summary>
  15. /// 设置锁定字段
  16. /// </summary>
  17. string AllPower1;
  18. public override string Text
  19. {
  20. get
  21. {
  22. return base.Text.Trim();
  23. }
  24. set
  25. {
  26. base.Text = value;
  27. }
  28. }
  29. public string AllPower
  30. {
  31. get { return AllPower1; }
  32. set { AllPower1 = value; }
  33. }
  34. public string ID
  35. {
  36. get { return ID1; }
  37. set { ID1 = value; }
  38. }
  39. public string Str
  40. {
  41. get { return str; }
  42. set { str = value; }
  43. }
  44. public string Str1
  45. {
  46. get { return str1; }
  47. set { str1 = value; }
  48. }
  49. public string Str2
  50. {
  51. get { return str2; }
  52. set { str2 = value; }
  53. }
  54. public string Power
  55. {
  56. get { return Power1; }
  57. set { Power1 = value; }
  58. }
  59. public EnterTextBox()
  60. {
  61. InitializeComponent();
  62. this.KeyDown += EnterTextBox_KeyDown;
  63. BackColor = System.Drawing.Color.White;
  64. }
  65. private void EnterTextBox_Enter(object sender, EventArgs e)
  66. {
  67. this.BackColor = Color.GreenYellow;
  68. }
  69. private void EnterTextBox_Leave(object sender, EventArgs e)
  70. {
  71. this.BackColor = Color.White;
  72. }
  73. //手动添加全选功能
  74. private void EnterTextBox_KeyDown(object sender, KeyEventArgs e)
  75. {
  76. if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.A)
  77. this.SelectAll();
  78. }
  79. private void EnterTextBox_KeyPress(object sender, KeyPressEventArgs e)
  80. {
  81. if (e.KeyChar == System.Convert.ToChar(13))
  82. {
  83. e.Handled = true;
  84. }
  85. }
  86. }
  87. }