Search code examples
c#winformsmaskedtextbox

MaskedTextBox not get value before delete old value


I used a MaskedTextBox on my winform and i fill a value from our database. But problem is that when the value is in the MaskedTextBox i can't write anything . But when i delete the value after that i can write in the MaskedTextBox . I set mask on that control is Time 'European Military ' means 24 hrs format . How can i resolve this. i validate it by below code

 private void maskedTextBox1_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
    {
        if (!e.IsValidInput)
        {
            e.Cancel = true;
            MessageBox.Show("Invalid time");
        }
    }

Solution

  • Can't write anything

    Sounds like you want this

    private void maskedTextBox1_Enter(object sender, EventArgs e)
    {
        maskedTextBox1.Focus();
        maskedTextBox1.SelectAll();
    }