Let us look at a simple C# Windows Forms MaskedTextBox example.
Example 1: MaskedTextBox
This example will comprise the following files:
MaskedTextBox.cs
Step 1: Create Project
- The first step is to create a C# Project.
- Go to
FILE-->New-->Project
to create a new project.
Step 2: Write Code
Write Code as follows:
*(a). MaskedTextBox.cs
Create a file named MaskedTextBox.cs
Here is the full code
using System;
using System.Windows.Forms;
namespace Examples {
class MainForm : Form {
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
public MainForm() {
Text = "MaskedTextBox example";
labelAge.Location = new System.Drawing.Point(10, 12);
labelAge.Text = "Phone";
labelAge.AutoSize = true;
maskedTextBoxAge.Location = new System.Drawing.Point(50, 10);
maskedTextBoxAge.Mask = "+999(999)99999999";
maskedTextBoxAge.Text = "";
Controls.AddRange(new Control[] { labelAge, maskedTextBoxAge });
}
private Label labelAge = new Label();
private MaskedTextBox maskedTextBoxAge = new MaskedTextBox();
}
}
Run
Simply copy the source code into your C# Project,Build and Run. Alternatively download the code using the links provided below, then open the .csproj
project, build and run.
Reference
Download the code using the below links:
Number | Link |
---|---|
1. | Download Example |
2. | Follow code author |