EnterTextBox.cs 2.4 KB

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