Underlines of MaskedTextBox disappear (Modal Form)

Flxxer 21 Reputation points
2021-09-23T12:45:46.567+00:00

Hello dear Coders,

I have a problem in Windows Forms. I've created a form where I can click on the search-Button to show another form with the following code:

Private Sub btnSearchUser_Click(sender As Object, e As EventArgs) Handles btnSearchUser.Click  
  
    If Me._clsfrmChild Is Nothing Then  
        Me._clsfrmChild = New clsFrmChild  
    End If  
  
    If Me._clsfrmChild.Visible = False Then   
        Me._clsfrmChild.ShowDialog(Me)  
    End If  

In the second form I have a MaskedTextbox:

134600-maskedtextbox1.png

I want to save the value which will be entered but the MaskedTextBox can remain empty as well. But it doesn't matter if the MaskedTextBox is filled or empty.

Whatever I do, if I close the second form with "Visible = False" and reopen it again, the MaskedTextbox looks like this:

134648-maskedtextbox2.png

I close the second form that way:

Private Sub btnAbort_Click(sender As Object, e As EventArgs) Handles btnAbort.Click  
    Me.Visible = False  
End Sub  

Does someone of you know why this problem is caused?

I think the problem has to be with ShowDialog(Me) but I can't replace ShowDialog() because it is required.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,839 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,581 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.7K Reputation points
    2021-09-23T20:36:25.96+00:00

    Try changing the TextMaskFormat of the textbox to IncludePromptAndLiterals.

    By the way, ‘If Me._clsfrmChild.ShowDialog = False’ does not seem to have sense because ShowDialog does not return a Boolean value.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,196 Reputation points
    2021-09-23T15:24:20.47+00:00

    For a test, comment out current code and use this and see if this fixes the issue, if it does then there is code in clsFrmChild preventing the MaskEditTextBox from properly initializing. If there is code in form load, move that code to the Shown event also.

    _clsfrmChild = New clsFrmChild
    _clsfrmChild.ShowDialog(Me)