EnterTextBox.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace UAS_MES.CustomControl.TextBoxWithIcon
  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 string AllPower
  19. {
  20. get { return AllPower1; }
  21. set { AllPower1 = value; }
  22. }
  23. public string ID
  24. {
  25. get { return ID1; }
  26. set { ID1 = value; }
  27. }
  28. public string Str
  29. {
  30. get { return str; }
  31. set { str = value; }
  32. }
  33. public string Str1
  34. {
  35. get { return str1; }
  36. set { str1 = value; }
  37. }
  38. public string Str2
  39. {
  40. get { return str2; }
  41. set { str2 = value; }
  42. }
  43. public string Power
  44. {
  45. get { return Power1; }
  46. set { Power1 = value; }
  47. }
  48. public EnterTextBox()
  49. {
  50. InitializeComponent();
  51. this.KeyDown += EnterTextBox_KeyDown;
  52. BackColor = System.Drawing.Color.White;
  53. }
  54. private void EnterTextBox_Enter(object sender, EventArgs e)
  55. {
  56. this.BackColor = Color.GreenYellow;
  57. }
  58. private void EnterTextBox_Leave(object sender, EventArgs e)
  59. {
  60. this.BackColor = Color.White;
  61. }
  62. //手动添加全选功能
  63. private void EnterTextBox_KeyDown(object sender, KeyEventArgs e)
  64. {
  65. if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.A)
  66. this.SelectAll();
  67. }
  68. }
  69. }