I have created a class that inherits from System.Windows.Forms.TextBox so I can add some functionality like a date mask, validating numeric types, etc. I have this block of code that handles MyBase.Enter and MyBase.GotFocus and does some stuff when the type of the textbox is Date. Basically what this code is attempting to do is format the text to a date format and then select the character that was clicked on.
The problem is that even though I'm setting the text of the base class in the Enter event the text is always String.Empty in the GotFocus event. I initially tried placing all of the code in the Enter event, but didn't have any success there so I moved the part that does the selection to the GotFocus event hoping that would cause the TextBox to accept the text. The interesting part is that after the events are complete the text is finally displayed in the textbox so the TextBox base class is eventually accepting the text sometime after the events have fired. I tried calling Application.DoEvents(), but that didn't help. Any idea as to how I can get the base TextBox class to accept the text at the time I set it? Here's the code: Private Sub MyTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Enter If m_enuType = TextBoxType.Date Then If IsDate(MyBase.Text) Then MyBase.Text = Format(CDate(MyBase.Text), "mm/dd/yyyy") Else MyBase.Text = " / / " End If End If End Sub Private Sub MyTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus If m_enuType = TextBoxType.Date Then ' this event always fires after the MyBase.Enter event. However, MyBase.Text is always String.Empty ' even though the Enter event handler always sets the text. What needs to be done to make ' MyBase accept the text? If MyBase.SelectionStart = 0 Or Mid(MyBase.Text, MyBase.SelectionStart + 1, 1) <> "/" Then ' select the next char MyBase.Select(MyBase.SelectionStart, 1) Else ' select the prev char MyBase.Select(MyBase.SelectionStart - 1, 1) End If End If End Sub Thanks, Roy You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.