InputBox.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:4k
- /*
- * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
- * $Id: InputBox.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
- */
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace Poderosa.Forms
- {
- /// <summary>
- /// InputBox 偺奣梫偺愢柧偱偡丅
- /// </summary>
- internal class InputBox : System.Windows.Forms.Form
- {
- private bool _allowsZeroLenString;
- private System.Windows.Forms.TextBox _textBox;
- private System.Windows.Forms.Button _okButton;
- private System.Windows.Forms.Button _cancelButton;
- /// <summary>
- /// 昁梫側僨僓僀僫曄悢偱偡丅
- /// </summary>
- private System.ComponentModel.Container components = null;
- public InputBox()
- {
- //
- // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
- //
- InitializeComponent();
- //
- // TODO: InitializeComponent 屇傃弌偟偺屻偵丄僐儞僗僩儔僋僞 僐乕僪傪捛壛偟偰偔偩偝偄丅
- //
- }
- public bool AllowsZeroLenString {
- get {
- return _allowsZeroLenString;
- }
- set {
- _allowsZeroLenString = value;
- }
- }
- /// <summary>
- /// 巊梡偝傟偰偄傞儕僜乕僗偵屻張棟傪幚峴偟傑偡丅
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 僼僅乕儉 僨僓僀僫偱惗惉偝傟偨僐乕僪
- /// <summary>
- /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
- /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
- /// </summary>
- private void InitializeComponent()
- {
- this._textBox = new System.Windows.Forms.TextBox();
- this._okButton = new System.Windows.Forms.Button();
- this._cancelButton = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // _textBox
- //
- this._textBox.Location = new System.Drawing.Point(8, 8);
- this._textBox.MaxLength = 30;
- this._textBox.Name = "_textBox";
- this._textBox.Size = new System.Drawing.Size(192, 19);
- this._textBox.TabIndex = 0;
- this._textBox.Text = "";
- this._textBox.GotFocus += new EventHandler(OnTextBoxGotFocus);
- this._textBox.TextChanged += new EventHandler(OnTextChanged);
- //
- // _okButton
- //
- this._okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
- this._okButton.Location = new System.Drawing.Point(48, 32);
- this._okButton.Name = "_okButton";
- this._okButton.FlatStyle = FlatStyle.System;
- this._okButton.Size = new System.Drawing.Size(64, 23);
- this._okButton.TabIndex = 1;
- this._okButton.Text = GApp.Strings.GetString("Common.OK");
- //
- // _cancelButton
- //
- this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
- this._cancelButton.Location = new System.Drawing.Point(128, 32);
- this._cancelButton.Name = "_cancelButton";
- this._cancelButton.FlatStyle = FlatStyle.System;
- this._cancelButton.Size = new System.Drawing.Size(72, 23);
- this._cancelButton.TabIndex = 2;
- this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
- //
- // InputBox
- //
- this.AcceptButton = this._okButton;
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
- this.CancelButton = this._cancelButton;
- this.ClientSize = new System.Drawing.Size(208, 61);
- this.Controls.Add(this._cancelButton);
- this.Controls.Add(this._okButton);
- this.Controls.Add(this._textBox);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "InputBox";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.ResumeLayout(false);
- }
- #endregion
- public string Content {
- get {
- return _textBox.Text;
- }
- set {
- _textBox.Text = value;
- _okButton.Enabled = _allowsZeroLenString || (value!=null && value.Length!=0);
- }
- }
- private void OnTextBoxGotFocus(object sender, EventArgs args) {
- _textBox.SelectAll(); //偙偺嫇摦偑朷傑偟偔側偄応崌傕偁傞偐傕偟傟側偄偑丄嵟弶偺梡搑偑僞僽偺僥僉僗僩曄峏側偺偱...
- }
- private void OnTextChanged(object sender, EventArgs args) {
- _okButton.Enabled = _allowsZeroLenString || (_textBox.Text!=null && _textBox.Text.Length!=0);
- }
- }
- }