Csharp/CSharp Tutorial/GUI Windows Forms/MaskedTextBox — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:31, 26 мая 2010

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.ruponentModel.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;
}

Set the input mask to that of a short date

using System;
using System.Threading;
using System.Windows.Forms;
public class MaskedTextBoxShortDateFormDemo{
    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new MaskedTextBoxShortDateForm());
    }
}
public partial class MaskedTextBoxShortDateForm : Form
{
    public MaskedTextBoxShortDateForm()
    {
        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)
    {
        this.mskTextBox.UseSystemPasswordChar = false;
        this.mskTextBox.Mask = "00/00/0000";
        this.lblActiveMask.Text = this.mskTextBox.Mask;
        this.mskTextBox.Focus();
    }
    private void btnSecret_Click(object sender, EventArgs e)
    {
    }
}
partial class MaskedTextBoxShortDateForm
{
    private System.ruponentModel.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 = "MaskedTextBoxShortDateForm";
        this.Text = "MaskedTextBoxShortDateForm";
        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;
}

Set the input mask to that of a short time

using System;
using System.Threading;
using System.Windows.Forms;
public class MaskedTextBoxShortTimeFormDemo{
    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new MaskedTextBoxShortTimeForm());
    }
}
public partial class MaskedTextBoxShortTimeForm : Form
{
    public MaskedTextBoxShortTimeForm()
    {
        InitializeComponent();
    }
    private void btnTime_Click(object sender, EventArgs e)
    {
        this.mskTextBox.UseSystemPasswordChar = false;
        this.mskTextBox.Mask = "00:00";
        this.lblActiveMask.Text = this.mskTextBox.Mask;
        this.mskTextBox.Focus();
    }
    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)
    {
    }
}
partial class MaskedTextBoxShortTimeForm
{
    private System.ruponentModel.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 = "MaskedTextBoxShortTimeForm";
        this.Text = "MaskedTextBoxShortTimeForm";
        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;
}

Set the input mask to that of a UK postcode

using System;
using System.Threading;
using System.Windows.Forms;
public class MaskedTextBoxUKPostCodeFormDemo{
    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new MaskedTextBoxUKPostCodeForm());
    }
}
public partial class MaskedTextBoxUKPostCodeForm : Form
{
    public MaskedTextBoxUKPostCodeForm()
    {
        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)
    {
        this.mskTextBox.UseSystemPasswordChar = false;
        this.mskTextBox.Mask = ">LCCC 9LL";
        this.lblActiveMask.Text = this.mskTextBox.Mask;
        this.mskTextBox.Focus();
    }
    private void btnCurrency_Click(object sender, EventArgs e)
    {
    }
    private void btnDate_Click(object sender, EventArgs e)
    {
    }
    private void btnSecret_Click(object sender, EventArgs e)
    {
    }
}
partial class MaskedTextBoxUKPostCodeForm
{
    private System.ruponentModel.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 = "MaskedTextBoxUKPostCodeForm";
        this.Text = "MaskedTextBoxUKPostCodeForm";
        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;
}

Set the input mask to that of a US ZIP code

using System;
using System.Threading;
using System.Windows.Forms;
public class MaskedTextBoxUSZipFormDemo{
    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new MaskedTextBoxUSZipForm());
    }
}
public partial class MaskedTextBoxUSZipForm : Form
{
    public MaskedTextBoxUSZipForm()
    {
        InitializeComponent();
    }
    private void btnTime_Click(object sender, EventArgs e)
    {
    }
    private void btnUSZip_Click(object sender, EventArgs e)
    {
        this.mskTextBox.UseSystemPasswordChar = false;
        this.mskTextBox.Mask = "00000-9999";
        this.lblActiveMask.Text = this.mskTextBox.Mask;
        this.mskTextBox.Focus();
    }
    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)
    {
    }
}
partial class MaskedTextBoxUSZipForm
{
    private System.ruponentModel.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 = "MaskedTextBoxUSZipForm";
        this.Text = "MaskedTextBoxUSZipForm";
        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;
}

Set the input mask to that of currency

using System;
using System.Threading;
using System.Windows.Forms;
public class MaskedTextBoxCurrencyFormDemo{
    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new MaskedTextBoxCurrencyForm());
    }
}
public partial class MaskedTextBoxCurrencyForm : Form
{
    public MaskedTextBoxCurrencyForm()
    {
        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)
    {
        this.mskTextBox.UseSystemPasswordChar = false;
        this.mskTextBox.Mask = ">LCCC 9LL";
        this.lblActiveMask.Text = this.mskTextBox.Mask;
        this.mskTextBox.Focus();
    }
    private void btnDate_Click(object sender, EventArgs e)
    {
    }
    private void btnSecret_Click(object sender, EventArgs e)
    {
    }
}
partial class MaskedTextBoxCurrencyForm
{
    private System.ruponentModel.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 = "MaskedTextBoxCurrencyForm";
        this.Text = "MaskedTextBoxCurrencyForm";
        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;
}