Password field : Password Field « GUI Windows Forms « C# / CSharp Tutorial






Password field
using System;
using System.ComponentModel;
using System.Windows.Forms;

public class TextForm : System.Windows.Forms.Form
{
    private System.ComponentModel.Container components = null;
  private System.Windows.Forms.Button btnPasswordDecoderRing;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.TextBox passwordBox;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.TextBox capsOnlyBox;
  private System.Windows.Forms.Button btnGetMultiLineText;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.TextBox multiLineBox;

    public TextForm()
    {
        InitializeComponent();
    CenterToScreen();
    }

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

  private void InitializeComponent()
  {
    this.capsOnlyBox = new System.Windows.Forms.TextBox();
    this.multiLineBox = new System.Windows.Forms.TextBox();
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.passwordBox = new System.Windows.Forms.TextBox();
    this.btnGetMultiLineText = new System.Windows.Forms.Button();
    this.btnPasswordDecoderRing = new System.Windows.Forms.Button();
    this.label3 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // capsOnlyBox
    // 
    this.capsOnlyBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
    this.capsOnlyBox.Location = new System.Drawing.Point(14, 176);
    this.capsOnlyBox.Name = "capsOnlyBox";
    this.capsOnlyBox.Size = new System.Drawing.Size(120, 20);
    this.capsOnlyBox.TabIndex = 3;
    this.capsOnlyBox.Text = "";
    // 
    // multiLineBox
    // 
    this.multiLineBox.AcceptsReturn = true;
    this.multiLineBox.AcceptsTab = true;
    this.multiLineBox.Location = new System.Drawing.Point(152, 8);
    this.multiLineBox.Multiline = true;
    this.multiLineBox.Name = "multiLineBox";
    this.multiLineBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
    this.multiLineBox.Size = new System.Drawing.Size(240, 104);
    this.multiLineBox.TabIndex = 0;
    this.multiLineBox.Text = "Type some stuff here (and hit the return and tab keys...)";
    // 
    // label1
    // 
    this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F);
    this.label1.Location = new System.Drawing.Point(8, 8);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(136, 56);
    this.label1.TabIndex = 1;
    this.label1.Text = "A multiline textbox that accepts tabs and return keystrokes.";
    // 
    // label2
    // 
    this.label2.Font = new System.Drawing.Font("Comic Sans MS", 12F);
    this.label2.Location = new System.Drawing.Point(14, 144);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(106, 24);
    this.label2.TabIndex = 4;
    this.label2.Text = "Caps only!!";
    // 
    // passwordBox
    // 
    this.passwordBox.Location = new System.Drawing.Point(160, 176);
    this.passwordBox.Name = "passwordBox";
    this.passwordBox.PasswordChar = '$';
    this.passwordBox.Size = new System.Drawing.Size(232, 20);
    this.passwordBox.TabIndex = 5;
    this.passwordBox.Text = "COM seems so old fashion";
    // 
    // btnGetMultiLineText
    // 
    this.btnGetMultiLineText.Location = new System.Drawing.Point(13, 72);
    this.btnGetMultiLineText.Name = "btnGetMultiLineText";
    this.btnGetMultiLineText.Size = new System.Drawing.Size(120, 32);
    this.btnGetMultiLineText.TabIndex = 2;
    this.btnGetMultiLineText.Text = "Get Text";
    this.btnGetMultiLineText.Click += new System.EventHandler(this.btnGetMultiLineText_Click);
    // 
    // btnPasswordDecoderRing
    // 
    this.btnPasswordDecoderRing.Location = new System.Drawing.Point(280, 144);
    this.btnPasswordDecoderRing.Name = "btnPasswordDecoderRing";
    this.btnPasswordDecoderRing.Size = new System.Drawing.Size(112, 24);
    this.btnPasswordDecoderRing.TabIndex = 7;
    this.btnPasswordDecoderRing.Text = "Decode Password";
    this.btnPasswordDecoderRing.Click += new System.EventHandler(this.btnPasswordDecoderRing_Click);
    // 
    // label3
    // 
    this.label3.Font = new System.Drawing.Font("Comic Sans MS", 12F);
    this.label3.Location = new System.Drawing.Point(152, 144);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(120, 24);
    this.label3.TabIndex = 6;
    this.label3.Text = "Password Box";
    // 
    // TextForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(408, 221);
    this.Controls.Add(this.btnPasswordDecoderRing);
    this.Controls.Add(this.label3);
    this.Controls.Add(this.passwordBox);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.capsOnlyBox);
    this.Controls.Add(this.btnGetMultiLineText);
    this.Controls.Add(this.label1);
    this.Controls.Add(this.multiLineBox);
    this.Name = "TextForm";
    this.Text = "TextBox Types";
    this.ResumeLayout(false);

  }

  protected void btnPasswordDecoderRing_Click (object sender, System.EventArgs e)
  {
    MessageBox.Show(passwordBox.Text, "Your password is:");
  }

  protected void btnGetMultiLineText_Click (object sender, System.EventArgs e)
  {
    MessageBox.Show(multiLineBox.Text, "Here is your text");
  }

    public static void Main(string[] args) 
    {
        Application.Run(new TextForm());
    }
}








23.19.Password Field
23.19.1.Password fieldPassword field
23.19.2.Password fields matchPassword fields match