0
 Good morning. I have a problem I hope you can help with. I have a simple production management package consisting of about 15 programs. To help with consistency and reduce typing and bugs, I created a group of subclassed .net controls (Controls.vb) that I compile into a dll. That code does things like change the background color of a textbox or formats a value when the textbox loses focus. I've added some properties that are handy to me like Required, ShowList and ListOnly. I use those events and properties in all my programs.

Recently I decided to use the Validating and Validated events. In program Distributor, the Validating event in both Controls and my forms are called as expected. In program Feature, however, neither Validating or Validated occur for any control in either Controls or Feature. In an effort to find the issue, I created a test project containing my subclassed controls code, program Feature and a small test program, Test. I began to copy all the control related code from Feature to Test, testing after each chunk. T continues to work fine with exactly the same control code while F continues to fail. At this point I've duplicated Feature in Test, so I suspect that it's a configuration issue. I've read all the Microsoft's docs about Validating, Validated, and CausesValidation and found no mention of those events being sensitive to the configuration. It should work everywhere.

Now I'm stuck. Distributor, Feature, Test and Controls are all using framework 4.8.1. In comparing the properties of F and T, the only difference I could see is that Test has Compile/Platform set to 'Active (Any CPU)', while Feature is 'Active (x86)'. Strangely, there's no option to change that setting. The pull-down only has the assigned value available.

I think I'm probably missing something stupid obvious, but I don't see it. :)

Finally, here's how I use the subclassed controls in my programs. This is the code that works fine in Distributor and Test but fails in Feature.

In the form load event are the lines:

  For Each c As Control In Me.Controls
     If c.HasChildren Then SetHandler(c)
  Next

End Sub

Private Sub SetHandler(ParentCtrl As Control)

  For Each c As Control In ParentCtrl.Controls
     If c.HasChildren Then
        SetHandler(c)
     Else
        If TypeOf c Is TextBox Then
           AddHandler c.Enter, AddressOf Control_Enter
           AddHandler c.KeyUp, AddressOf Control_KeyUp
           AddHandler c.Leave, AddressOf Control_Leave
           AddHandler c.Validating, AddressOf Control_Validating
           AddHandler c.HelpRequested, AddressOf Control_Help
        ElseIf TypeOf c Is Button Then
           AddHandler c.Click, AddressOf btn_Click
           AddHandler c.Validating, AddressOf Control_Validating
           AddHandler c.HelpRequested, AddressOf Control_Help
        ElseIf TypeOf c Is ...
        .
        .
        .
        End If
     End If
  End If

End Sub

Private Sub Control_Validating(sender As Object, e As CancelEventArgs)

  'works in Distributor and Test, but never gets called in Feature
  Dim c = CType(sender, pwTextBox)
  ftxtDesc.Text = "validating " & c.Name

End Sub

The code in controls.dll Validating event (subclassed textbox)

Sub Me_Validating(sender As Object, e As CancelEventArgs) Handles MyBase.Validating

  Dim c = CType(sender, TextBox)

  Dim ok As Boolean = True
  If Text = "" Then
     ok = Not Required
  Else
     If xCalText Then
        MyBase.BackColor = If(IsDate(Text), defBackColor, defErrColor)
     Else
        Select Case xTextType
           Case enumTextType.Intgr : ok = Regex.IsMatch(Text, "^[0-9-,]+$")
           Case enumTextType.Money : ok = Regex.IsMatch(Text, "^[0-9-,\.]+$")
           Case enumTextType.Size : ok = Regex.IsMatch(Text, "^[0-9-/ \.]+$")
           Case enumTextType.Qty : ok = Regex.IsMatch(Text, "^[0-9-.,]+$")
           Case enumTextType.Zip : ok = Regex.IsMatch(Text, "^[0-9-]+$")
           Case enumTextType.Phone   'handle in client code because of foreign numbers
           Case enumTextType.Email : ok = Regex.IsMatch(Text, "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$")
        End Select
     End If
  End If
  MyBase.BackColor = If(ok, defBackColor, defErrColor)

End Sub

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.