ucLetterNumberKey.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace MeterModuleLibrary
  11. {
  12. public partial class ucLetterNumberKey : UserControl
  13. {
  14. public ucLetterNumberKey()
  15. {
  16. InitializeComponent();
  17. }
  18. public string strValue = "";
  19. private void btnSetValue_Click(object sender, EventArgs e)
  20. {
  21. Button btn = (Button)sender;
  22. int i = txtValue.SelectionStart;
  23. if (btn.Name == "btn00")
  24. {
  25. i++;
  26. }
  27. txtValue.Focus();
  28. txtValue.Text = txtValue.Text.Trim() + btn.Text;
  29. txtValue.Select(++i, 0);
  30. }
  31. private void btnClean_Click(object sender, EventArgs e)
  32. {
  33. txtValue.Text = "";
  34. }
  35. private void btnSubmit_Click(object sender, EventArgs e)
  36. {
  37. strValue = txtValue.Text.Trim();
  38. txtValue.Text = "";
  39. //此处还需调用加载该用户控件的界面关闭方法
  40. }
  41. private void btnBack_Click(object sender, EventArgs e)
  42. {
  43. int i = txtValue.SelectionStart;
  44. txtValue.Focus();
  45. if (i > 0)
  46. {
  47. txtValue.Text = txtValue.Text.Trim().Substring(0, i - 1) + txtValue.Text.Trim().Substring(i);
  48. txtValue.Select(--i, 0);
  49. }
  50. }
  51. private void btnLeft_Click(object sender, EventArgs e)
  52. {
  53. int i = txtValue.SelectionStart;
  54. txtValue.Focus();
  55. if (i>0)
  56. txtValue.Select(--i, 0);
  57. }
  58. private void btnRight_Click(object sender, EventArgs e)
  59. {
  60. int i = txtValue.SelectionStart;
  61. txtValue.Focus();
  62. if (i < txtValue.Text.Trim().Length)
  63. txtValue.Select(++i, 0);
  64. }
  65. }
  66. }