InputBox.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:4k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: InputBox.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.Drawing;
  7. using System.Collections;
  8. using System.ComponentModel;
  9. using System.Windows.Forms;
  10. namespace Poderosa.Forms
  11. {
  12. /// <summary>
  13. /// InputBox 偺奣梫偺愢柧偱偡丅
  14. /// </summary>
  15. internal class InputBox : System.Windows.Forms.Form
  16. {
  17. private bool _allowsZeroLenString;
  18. private System.Windows.Forms.TextBox _textBox;
  19. private System.Windows.Forms.Button _okButton;
  20. private System.Windows.Forms.Button _cancelButton;
  21. /// <summary>
  22. /// 昁梫側僨僓僀僫曄悢偱偡丅
  23. /// </summary>
  24. private System.ComponentModel.Container components = null;
  25. public InputBox()
  26. {
  27. //
  28. // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
  29. //
  30. InitializeComponent();
  31. //
  32. // TODO: InitializeComponent 屇傃弌偟偺屻偵丄僐儞僗僩儔僋僞 僐乕僪傪捛壛偟偰偔偩偝偄丅
  33. //
  34. }
  35. public bool AllowsZeroLenString {
  36. get {
  37. return _allowsZeroLenString;
  38. }
  39. set {
  40. _allowsZeroLenString = value;
  41. }
  42. }
  43. /// <summary>
  44. /// 巊梡偝傟偰偄傞儕僜乕僗偵屻張棟傪幚峴偟傑偡丅
  45. /// </summary>
  46. protected override void Dispose( bool disposing )
  47. {
  48. if( disposing )
  49. {
  50. if(components != null)
  51. {
  52. components.Dispose();
  53. }
  54. }
  55. base.Dispose( disposing );
  56. }
  57. #region Windows 僼僅乕儉 僨僓僀僫偱惗惉偝傟偨僐乕僪 
  58. /// <summary>
  59. /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
  60. /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. this._textBox = new System.Windows.Forms.TextBox();
  65. this._okButton = new System.Windows.Forms.Button();
  66. this._cancelButton = new System.Windows.Forms.Button();
  67. this.SuspendLayout();
  68. // 
  69. // _textBox
  70. // 
  71. this._textBox.Location = new System.Drawing.Point(8, 8);
  72. this._textBox.MaxLength = 30;
  73. this._textBox.Name = "_textBox";
  74. this._textBox.Size = new System.Drawing.Size(192, 19);
  75. this._textBox.TabIndex = 0;
  76. this._textBox.Text = "";
  77. this._textBox.GotFocus += new EventHandler(OnTextBoxGotFocus);
  78. this._textBox.TextChanged += new EventHandler(OnTextChanged);
  79. // 
  80. // _okButton
  81. // 
  82. this._okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  83. this._okButton.Location = new System.Drawing.Point(48, 32);
  84. this._okButton.Name = "_okButton";
  85. this._okButton.FlatStyle = FlatStyle.System;
  86. this._okButton.Size = new System.Drawing.Size(64, 23);
  87. this._okButton.TabIndex = 1;
  88. this._okButton.Text = GApp.Strings.GetString("Common.OK");
  89. // 
  90. // _cancelButton
  91. // 
  92. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  93. this._cancelButton.Location = new System.Drawing.Point(128, 32);
  94. this._cancelButton.Name = "_cancelButton";
  95. this._cancelButton.FlatStyle = FlatStyle.System;
  96. this._cancelButton.Size = new System.Drawing.Size(72, 23);
  97. this._cancelButton.TabIndex = 2;
  98. this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
  99. // 
  100. // InputBox
  101. // 
  102. this.AcceptButton = this._okButton;
  103. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  104. this.CancelButton = this._cancelButton;
  105. this.ClientSize = new System.Drawing.Size(208, 61);
  106. this.Controls.Add(this._cancelButton);
  107. this.Controls.Add(this._okButton);
  108. this.Controls.Add(this._textBox);
  109. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  110. this.MaximizeBox = false;
  111. this.MinimizeBox = false;
  112. this.Name = "InputBox";
  113. this.ShowInTaskbar = false;
  114. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  115. this.ResumeLayout(false);
  116. }
  117. #endregion
  118. public string Content {
  119. get {
  120. return _textBox.Text;
  121. }
  122. set {
  123. _textBox.Text = value;
  124. _okButton.Enabled = _allowsZeroLenString || (value!=null && value.Length!=0);
  125. }
  126. }
  127. private void OnTextBoxGotFocus(object sender, EventArgs args) {
  128. _textBox.SelectAll(); //偙偺嫇摦偑朷傑偟偔側偄応崌傕偁傞偐傕偟傟側偄偑丄嵟弶偺梡搑偑僞僽偺僥僉僗僩曄峏側偺偱...
  129. }
  130. private void OnTextChanged(object sender, EventArgs args) {
  131. _okButton.Enabled = _allowsZeroLenString || (_textBox.Text!=null && _textBox.Text.Length!=0);
  132. }
  133. }
  134. }