-1
Type I wanted to know if there is any way to create a format whenever the user type some characters (ex: 8 for phone and 9 for mobile), already identify and apply in the textbox. Or when the user enters a specific character already identify that is the phone or mobile number (ex: when entering the number 9 already identify and apply the format to mobile). Or some other way to apply the 2 in a single textbox.
below is a code I made for phone in case it is useful.
private void Tel(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) || e.KeyChar == (char)(Keys.Back))
{
e.Handled = false;
if (e.KeyChar == (char)(Keys.Back))
{
txtTel.Text = "";
}
if (txtTel.Text.Length == 0)
{
txtTel.Text += "(";
}
if (txtTel.Text.Length == 6)
{
txtTel.Text += ")";
}
if (txtTel.Text.Length == 2)
{
txtTel.Text += "X";
}
if (txtTel.Text.Length == 3)
{
txtTel.Text += "X";
}
if (txtTel.Text.Length == 11)
{
txtTel.Text += "-";
}
}
else
{
e.Handled = true;
}
txtTel.SelectionStart = txtTel.TextLength + 1;