FrmInputDialog.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace SheepSheep
  11. {
  12. public partial class FrmInputDialog : Form
  13. {
  14. public delegate void TextEventHandler(string strText);
  15. public TextEventHandler TextHandler;
  16. public FrmInputDialog(string title)
  17. {
  18. InitializeComponent();
  19. this.Text = title;
  20. }
  21. private void btnOk_Click(object sender, EventArgs e)
  22. {
  23. if (null != TextHandler)
  24. {
  25. TextHandler.Invoke(txtString.Text);
  26. DialogResult = DialogResult.OK;
  27. }
  28. }
  29. private void btnCancel_Click(object sender, EventArgs e)
  30. {
  31. DialogResult = DialogResult.Cancel;
  32. }
  33. private void txtString_KeyPress(object sender, KeyPressEventArgs e)
  34. {
  35. if (e.KeyChar != '\b')
  36. {
  37. if ((e.KeyChar < '0') || (e.KeyChar > '9'))
  38. {
  39. e.Handled = true;
  40. }
  41. }
  42. if (Keys.Enter == (Keys)e.KeyChar)
  43. {
  44. if (null != TextHandler)
  45. {
  46. TextHandler.Invoke(txtString.Text);
  47. DialogResult = DialogResult.OK;
  48. }
  49. }
  50. }
  51. }
  52. }