Reputation: 11
How can I use a mask for the textbox?
I am using Guna2 framework and there is no MaskedTextBox there.
You need to make a mask manually. I tried some options from the internet, but they didn't work.
Before that, I tried handling keyboard presses and separating with dots after every 2 characters. But this is a bad way. Who knows how to do it using DateTime or other methods?
private void guna2TextBox20_TextChanged(object sender, EventArgs e)
{
guna2TextBox20.Text = GetMaskedString("dd.MM/yyyy",guna2TextBox20.Text);
}
public static string GetMaskedString(string mask, string input)
{
try
{
MaskedTextProvider provider = new MaskedTextProvider(mask);
provider.Add(input);
return provider.ToDisplayString();
}
catch { return input; }
}
I've tried this. Works, but enters the date backwards
private void guna2TextBox20_TextChanged(object sender, EventArgs e)
{
MaskedTextBox mask = new MaskedTextBox();
mask.Mask = "00/00/0000";
mask.Text = guna2TextBox20.Text;
guna2TextBox20.Text = mask.Text;
}
Upvotes: 0
Views: 3312
Reputation: 9
Just add a MaskedTextBox control to your form and put its visibility to false.
It would create a mapping system which your MaskedTextProvider would be using
MaskedTextBox control is a part of Windows Forms and should be available in the Toolbox like in this screen shot
Upvotes: 1