NumOnlyTextBox.cs 904 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Windows.Forms;
  2. namespace UAS_MES_NEW.CustomControl.TextBoxWithIcon
  3. {
  4. public partial class NumOnlyTextBox : EnterTextBox
  5. {
  6. private bool Negative1;
  7. public NumOnlyTextBox()
  8. {
  9. InitializeComponent();
  10. }
  11. //通过标识来判断是否允许输入负数
  12. public bool Negative
  13. {
  14. get
  15. {
  16. return Negative1;
  17. }
  18. set
  19. {
  20. Negative1 = value;
  21. }
  22. }
  23. private void NumOnlyTextBox_KeyPress(object sender, KeyPressEventArgs e)
  24. {
  25. // 允许输入:数字、退格键(8)、全选(1)、复制(3)、粘贴(22)
  26. if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8 && e.KeyChar != 1 && e.KeyChar != 3 && e.KeyChar != 22)
  27. {
  28. e.Handled = true;
  29. }
  30. }
  31. }
  32. }