Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Simple input box... (See related posts)

// Simple input box class: call by InputBox.ShowInputBox()

	public class InputBox : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textBox1;
		private System.ComponentModel.Container components = null;

		private InputBox()
		{
			InitializeComponent();
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		private void InitializeComponent()
		{
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			//
			// textBox1
			//
			this.textBox1.Location = new System.Drawing.Point(16, 16);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(256, 20);
			this.textBox1.TabIndex = 0;
			this.textBox1.PasswordChar='*';
			this.textBox1.Text = "textBox1";
			this.textBox1.KeyDown += new
				System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
			//
			// InputBox
			//
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 53);
			this.ControlBox = false;
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.textBox1});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "InputBox";
			this.Text = "Password";
			this.StartPosition = FormStartPosition.CenterParent;
			this.ResumeLayout(false);			

		}

		private void textBox1_KeyDown(object sender,
			System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode == Keys.Enter)
				this.Close();
			if(e.KeyCode == Keys.Escape)
			{
              	textBox1.Text="";
				this.Close();
			}				
		}

		public static string ShowInputBox()
		{
			InputBox box = new InputBox();
			box.ShowDialog();
			return box.textBox1.Text;
		}    
	}

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts