In a VB.Net 2017 Windows Forms project, I've defined a user control (named "ExDatePicker") that includes a label, a textbox (named "txt") and a datetimepicker. In several places, I'm passing specific instances of that user control to the Sub shown below. This seems to work as intended for most of the instances, but for one of them it fails to change txt.BackColor. When I step through the code, it APPEARS to change the .BackColor value but that change is never reflected on the screen. At first, the user control parameter ("exdtp") was defined as ByVal and I thought that was the problem. But even after changing it to ByRef, the problem persists. Any ideas about what might be causing this?
Code:Public Sub CheckDateTimePicker(ByRef exdtp As ExDatePicker, ByRef Message As String, Optional IsRequired As Boolean = False, Optional MinValue As Date = MinDateValue, Optional MaxValue As Date = MaxDateValue) Dim OldMessage As String, Temp As String, Dt As Date OldMessage = Message Temp = exdtp.txt.Text If Date.TryParse(Temp, Dt) Then If (Dt < MinValue) Or (Dt > MaxValue) Then AddText(Message, exdtp.DisplayName & " must be between " & FormatDate(MinValue.ToString) & " and " & FormatDate(MaxValue.ToString) & ".") End If Else If IsRequired Then AddText(Message, exdtp.DisplayName & " is required.") End If End If 'set .BackColor to reflect whether any edit checks failed exdtp.txt.BackColor = If(Message = OldMessage, NormalBackColor, WarningBackColor) End Sub




Reply With Quote
