Typing in the TextBox

0

I'm doing a project in visual studio and need help. I would like to know if you have how or how to do that when I type in the textbox, this that I typed in starts regardless of the position of the cursor or that it goes kinda deleting until you get to the front. The textbox would be over or less so: (__)

asked by anonymous 04.06.2016 / 01:36

1 answer

2

You can use the Enter event of the MaskedTextBox to be triggered whenever the user clicks on the component and uses the Select method as follows:

In the method below, it is also validated if the TextBox is empty to put the cursor at the beginning.

To use this way, you need to change the TextMaskFormat property to ExcludePromptAndLiterals . - This will cause the Text property of the TextBox to contain only the text entered by the user.

private void maskedTextBox1_Enter(object sender, EventArgs e)
{
    var txtbox = (MaskedTextBox)sender;
    if (string.IsNullOrWhiteSpace(txtbox.Text))
    {
        this.BeginInvoke((MethodInvoker)(() => txtbox.Select(0, 0)));
    }
}
    
04.06.2016 / 16:19