MaCodeTextBox.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using UAS_MES.PublicMethod;
  5. namespace UAS_MES.CustomControl.TextBoxWithIcon
  6. {
  7. public partial class MaCodeTextBox : 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. private bool Lock1;
  19. string AllPower1;
  20. public string AllPower
  21. {
  22. get { return AllPower1; }
  23. set { AllPower1 = value; }
  24. }
  25. public string ID
  26. {
  27. get { return ID1; }
  28. set { ID1 = value; }
  29. }
  30. public string Str
  31. {
  32. get { return str; }
  33. set { str = value; }
  34. }
  35. public string Str1
  36. {
  37. get { return str1; }
  38. set { str1 = value; }
  39. }
  40. public string Str2
  41. {
  42. get { return str2; }
  43. set { str2 = value; }
  44. }
  45. public string Power
  46. {
  47. get { return Power1; }
  48. set { Power1 = value; }
  49. }
  50. public bool Lock
  51. {
  52. get { return Lock1; }
  53. set { Lock1 = value; }
  54. }
  55. public MaCodeTextBox()
  56. {
  57. InitializeComponent();
  58. this.KeyDown += MaCodeTextBox_KeyDown;
  59. BackColor = System.Drawing.Color.White;
  60. }
  61. private void EnterTextBox_Enter(object sender, EventArgs e)
  62. {
  63. this.BackColor = Color.GreenYellow;
  64. }
  65. private void EnterTextBox_Leave(object sender, EventArgs e)
  66. {
  67. this.BackColor = Color.White;
  68. }
  69. //手动添加全选功能
  70. private void MaCodeTextBox_KeyDown(object sender, KeyEventArgs e)
  71. {
  72. if (e.Modifiers.CompareTo(Keys.Control) == 0 && e.KeyCode == Keys.A)
  73. this.SelectAll();
  74. if (e.KeyCode == Keys.Enter)
  75. {
  76. if (Text != "")
  77. {
  78. string ErrorMessage = "";
  79. if (!LogicHandler.CheckMakeStatus(Text, out ErrorMessage))
  80. {
  81. Text = "";
  82. BaseUtil.ShowError(ErrorMessage);
  83. }
  84. }
  85. else
  86. BaseUtil.ShowError("工单号不能为空");
  87. }
  88. }
  89. }
  90. }