InputBox.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. namespace IndexFormula.Finance.Win
  2. {
  3. using System;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. [ToolboxItem(false)]
  8. public class InputBox : Form
  9. {
  10. private Button btnOK;
  11. private Container components = null;
  12. private Label lCaption;
  13. private TextBox tbData;
  14. private InputBox()
  15. {
  16. this.InitializeComponent();
  17. }
  18. protected override void Dispose(bool disposing)
  19. {
  20. if (disposing && (this.components != null))
  21. {
  22. this.components.Dispose();
  23. }
  24. base.Dispose(disposing);
  25. }
  26. private void InitializeComponent()
  27. {
  28. this.lCaption = new Label();
  29. this.tbData = new TextBox();
  30. this.btnOK = new Button();
  31. base.SuspendLayout();
  32. this.lCaption.Location = new Point(8, 11);
  33. this.lCaption.Name = "lCaption";
  34. this.lCaption.Size = new Size(0x68, 0x10);
  35. this.lCaption.TabIndex = 0;
  36. this.lCaption.Text = "Your Text:";
  37. this.lCaption.TextAlign = ContentAlignment.MiddleLeft;
  38. this.tbData.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
  39. this.tbData.Location = new Point(8, 0x25);
  40. this.tbData.Name = "tbData";
  41. this.tbData.Size = new Size(400, 0x15);
  42. this.tbData.TabIndex = 1;
  43. this.tbData.Text = "";
  44. this.tbData.KeyDown += new KeyEventHandler(this.tbData_KeyDown);
  45. this.btnOK.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
  46. this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
  47. this.btnOK.Location = new Point(0x14d, 0x41);
  48. this.btnOK.Name = "btnOK";
  49. this.btnOK.TabIndex = 2;
  50. this.btnOK.Text = "OK";
  51. this.AutoScaleBaseSize = new Size(6, 14);
  52. base.ClientSize = new Size(0x1a2, 0x5f);
  53. base.Controls.Add(this.btnOK);
  54. base.Controls.Add(this.tbData);
  55. base.Controls.Add(this.lCaption);
  56. this.Font = new Font("Verdana", 8.5f);
  57. base.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  58. base.KeyPreview = true;
  59. base.MaximizeBox = false;
  60. base.MinimizeBox = false;
  61. base.Name = "InputBox";
  62. base.StartPosition = FormStartPosition.CenterParent;
  63. this.Text = "InputBox";
  64. base.KeyDown += new KeyEventHandler(this.InputBox_KeyDown);
  65. base.ResumeLayout(false);
  66. }
  67. private void InputBox_KeyDown(object sender, KeyEventArgs e)
  68. {
  69. if (e.KeyCode == Keys.Escape)
  70. {
  71. base.Close();
  72. }
  73. }
  74. public static string ShowInputBox(string Caption, string Default)
  75. {
  76. InputBox box = new InputBox();
  77. box.lCaption.Text = Caption;
  78. box.tbData.Text = Default;
  79. if (box.ShowDialog() == DialogResult.OK)
  80. {
  81. return box.tbData.Text;
  82. }
  83. return "";
  84. }
  85. private void tbData_KeyDown(object sender, KeyEventArgs e)
  86. {
  87. if (e.KeyCode == Keys.Enter)
  88. {
  89. this.btnOK.PerformClick();
  90. }
  91. }
  92. }
  93. }