Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Set the input mask to that of a secret PIN

using System; using System.Threading; using System.Windows.Forms; public class MaskedTextBoxPINFormDemo{     [STAThread]     public static void Main(string[] args)     {         Application.Run(new MaskedTextBoxPINForm());     } } public partial class MaskedTextBoxPINForm : Form {     public MaskedTextBoxPINForm()     {         InitializeComponent();     }     private void btnTime_Click(object sender, EventArgs e)     {     }     private void btnUSZip_Click(object sender, EventArgs e)     {     }     private void btnUKPost_Click(object sender, EventArgs e)     {     }     private void btnCurrency_Click(object sender, EventArgs e)     {     }     private void btnDate_Click(object sender, EventArgs e)     {     }     private void btnSecret_Click(object sender, EventArgs e)     {                  this.mskTextBox.UseSystemPasswordChar = true;         this.mskTextBox.Mask = "000-000-000";         this.lblActiveMask.Text = this.mskTextBox.Mask;         this.mskTextBox.Focus();     } } partial class MaskedTextBoxPINForm {     private System.ComponentModel.IContainer components = null;     protected override void Dispose(bool disposing)     {         if (disposing && (components != null))         {             components.Dispose();         }         base.Dispose(disposing);     }     private void InitializeComponent()     {         this.mskTextBox = new System.Windows.Forms.MaskedTextBox();         this.label1 = new System.Windows.Forms.Label();         this.lblActiveMask = new System.Windows.Forms.Label();         this.btnTime = new System.Windows.Forms.Button();         this.btnUSZip = new System.Windows.Forms.Button();         this.btnCurrency = new System.Windows.Forms.Button();         this.btnUKPost = new System.Windows.Forms.Button();         this.btnDate = new System.Windows.Forms.Button();         this.btnSecret = new System.Windows.Forms.Button();         this.SuspendLayout();         this.mskTextBox.BeepOnError = true;         this.mskTextBox.Location = new System.Drawing.Point(15, 41);         this.mskTextBox.Name = "mskTextBox";         this.mskTextBox.Size = new System.Drawing.Size(265, 20);         this.mskTextBox.TabIndex = 1;         this.label1.AutoSize = true;         this.label1.Location = new System.Drawing.Point(12, 23);         this.label1.Name = "label1";         this.label1.Size = new System.Drawing.Size(94, 13);         this.label1.TabIndex = 2;         this.label1.Text = "Active input mask:";         this.lblActiveMask.AutoSize = true;         this.lblActiveMask.Location = new System.Drawing.Point(112, 23);         this.lblActiveMask.Name = "lblActiveMask";         this.lblActiveMask.Size = new System.Drawing.Size(51, 13);         this.lblActiveMask.TabIndex = 3;         this.lblActiveMask.Text = "Any input";         this.btnTime.Location = new System.Drawing.Point(15, 85);         this.btnTime.Name = "btnTime";         this.btnTime.Size = new System.Drawing.Size(83, 23);         this.btnTime.TabIndex = 4;         this.btnTime.Text = "24-hour time";         this.btnTime.UseVisualStyleBackColor = true;         this.btnTime.Click += new System.EventHandler(this.btnTime_Click);         this.btnUSZip.Location = new System.Drawing.Point(15, 130);         this.btnUSZip.Name = "btnUSZip";         this.btnUSZip.Size = new System.Drawing.Size(83, 23);         this.btnUSZip.TabIndex = 5;         this.btnUSZip.Text = "US ZIP";         this.btnUSZip.UseVisualStyleBackColor = true;         this.btnUSZip.Click += new System.EventHandler(this.btnUSZip_Click);         this.btnCurrency.Location = new System.Drawing.Point(104, 85);         this.btnCurrency.Name = "btnCurrency";         this.btnCurrency.Size = new System.Drawing.Size(87, 23);         this.btnCurrency.TabIndex = 7;         this.btnCurrency.Text = "Currency";         this.btnCurrency.UseVisualStyleBackColor = true;         this.btnCurrency.Click += new System.EventHandler(this.btnCurrency_Click);         this.btnUKPost.Location = new System.Drawing.Point(104, 130);         this.btnUKPost.Name = "btnUKPost";         this.btnUKPost.Size = new System.Drawing.Size(87, 23);         this.btnUKPost.TabIndex = 8;         this.btnUKPost.Text = "UK Postcode";         this.btnUKPost.UseVisualStyleBackColor = true;         this.btnUKPost.Click += new System.EventHandler(this.btnUKPost_Click);         this.btnDate.Location = new System.Drawing.Point(197, 85);         this.btnDate.Name = "btnDate";         this.btnDate.Size = new System.Drawing.Size(83, 23);         this.btnDate.TabIndex = 10;         this.btnDate.Text = "Short Date";         this.btnDate.UseVisualStyleBackColor = true;         this.btnDate.Click += new System.EventHandler(this.btnDate_Click);         this.btnSecret.Location = new System.Drawing.Point(197, 130);         this.btnSecret.Name = "btnSecret";         this.btnSecret.Size = new System.Drawing.Size(83, 23);         this.btnSecret.TabIndex = 11;         this.btnSecret.Text = "Secret PIN";         this.btnSecret.UseVisualStyleBackColor = true;         this.btnSecret.Click += new System.EventHandler(this.btnSecret_Click);         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;         this.ClientSize = new System.Drawing.Size(292, 196);         this.Controls.Add(this.btnSecret);         this.Controls.Add(this.btnDate);         this.Controls.Add(this.btnUKPost);         this.Controls.Add(this.btnCurrency);         this.Controls.Add(this.btnUSZip);         this.Controls.Add(this.btnTime);         this.Controls.Add(this.lblActiveMask);         this.Controls.Add(this.label1);         this.Controls.Add(this.mskTextBox);         this.Name = "MaskedTextBoxPINForm";         this.Text = "MaskedTextBoxPINForm";         this.ResumeLayout(false);         this.PerformLayout();     }     private System.Windows.Forms.MaskedTextBox mskTextBox;     private System.Windows.Forms.Label label1;     private System.Windows.Forms.Label lblActiveMask;     private System.Windows.Forms.Button btnTime;     private System.Windows.Forms.Button btnUSZip;     private System.Windows.Forms.Button btnCurrency;     private System.Windows.Forms.Button btnUKPost;     private System.Windows.Forms.Button btnDate;     private System.Windows.Forms.Button btnSecret; }