To create dynamically Windows you can initially put one MaskedTextBox maskedTextBox = new MaskedTextBox();
and put all the settings you want and to instate, a Controls.Add(maskedTextBox);
. And to do what you want, Voce can do, so as each string size adds the bar in a text change event, look at an example, I used the Method DynamicallyMaskedTexBox()
to create the Maskedtextbox and maskedTextBox_TexChanged(object sender, System.EventArgs e)
for the event, look at the example:
namespace Forms
{
public partial class Form1 : Form
{
private MaskedTextBox maskedTextBox;
public Form1()
{
InitializeComponent();
DynamicallyMaskedTexBox();
}
private void DynamicallyMaskedTexBox()
{
maskedTextBox = new MaskedTextBox();
maskedTextBox.Name = "MaskedTexBox1";
maskedTextBox.Location = new Point(12,70);
maskedTextBox.Width = 100;
maskedTextBox.Height = 20;
maskedTextBox.TextChanged += new EventHandler(maskedTextBox_TexChanged);
Controls.Add(maskedTextBox);
}
private void maskedTextBox_TexChanged(object sender, System.EventArgs e)
{
string maskedText = "00000000";
try
{
if(maskedTextBox.Mask.Length < maskedText.Length/4)
{
maskedTextBox.Mask += "00";
maskedTextBox.SelectionStart = maskedTextBox.Text.Length;
maskedTextBox.SelectionLength = 0;
}
else if(maskedTextBox.Mask.Length == maskedText.Length/4)
{
maskedTextBox.Mask += "/";
}
else if(maskedTextBox.Mask.Length < maskedText.Length/2+1)
{
maskedTextBox.Mask += "0";
}
else if (maskedTextBox.Mask.Length == maskedText.Length / 2+1)
{
maskedTextBox.Mask += "/";
}
else if(maskedTextBox.Mask.Length >= maskedText.Length /2+2 && maskedTextBox.Mask.Length < maskedText.Length+2)
{
maskedTextBox.Mask += "0";
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
The answer is in your question. To create this effect you will need to use all these events and implement their behaviors.
– Leandro Angelo