Forum Discussion

sverweij's avatar
sverweij
New Contributor
14 years ago

TestComplete and Windows Forms MaskedTextBox

- Create Windows Forms project, add a MaskedTextBox to the form, give it a date mask e.g. "09/09/0000".



- Add a button, add this to the Click event handler

MsgBox(MaskedTextBox1.Text)


- Run, enter a date, click the button. You'll get a dialog showing the value.



Now do the same in a recorded TestComplete project. The value is set on-screen, but the value in the dialog is blank!



I'm evaluating TestComplete, and this sinks us pretty hard. My guess is that this is a bug in the MaskedTextBox, not necessarily TestComplete, but not working is not working...



Any ideas?


2 Replies

  • sverweij's avatar
    sverweij
    New Contributor
    Figured it out:



    ''' <summary>


    ''' Simple wrapper around MaskedTextBox. Exists solely because MaskedTextBox does not respond to


    ''' WM_SETTEXT messages, and it needs to in order to be used with testing tools.


    ''' </summary>


    Friend NotInheritable Class MaskedTextBoxWrapper


    Inherits MaskedTextBox


    Private Const WM_SETTEXT As Integer = &HC


    Protected Overrides Sub WndProc(ByRef message As Message)


    If message.Msg = WM_SETTEXT Then


    Dim value As String = Marshal.PtrToStringUni(message.LParam)


    MyBase.Text = value


    End If


    MyBase.WndProc(message)


    End Sub


    End Class

  • sverweij's avatar
    sverweij
    New Contributor
    To be more specific, TestComplete picks the SetText operation, which does not do anything on a MaskedTextBox. Manually changing it to set the property (Text [Set]) works just fine, but doing that for every date field in our app is not happening, obviously.



    What, exactly, does SetText do under the hood? Can I perhaps hook into WndProc?