sburleson
Programmer
- Oct 14, 2002
- 14
I have created a usercontrol that contains a DateTimePicker and a Label. The idea is that I would like to show the date/time picker when it is enabled but a text representation when it is disabled. I would like to be able to override the default colors that are used by this control. Ironically, this problem was addressed in a similiar manner by this discussion: thread796-960474
However, I am having a problem with my solution with the forecolor. I have an exposed property:
Public Property Sub DisabledForeColor
Get
Return lDateTime.ForeColor
End Get
Set (Value As Color)
lDateTime.ForeColor = Value
End Set
End Property
This seems to work properly. If I change this property and I examine lDateTimeLabel.ForeColor in a debugger, I can see that it has the correct value. The core of what I want to do is done by overriding the OnEnabledChange method:
Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
If Enabled() Then
dtDateTimePicker.Enabled = True
dtDateTimePicker.Show()
lDateTime.Hide()
Else
dtDateTimePicker.Enabled = False
dtDateTimePicker.Hide()
lDateTime.Show()
End If
MyBase.OnEnabledChanged(e)
End Sub
Again, when I examine lDateTime.ForeColor in the debugger right before Show is called, it has the correct value (I have experimented with Color.White and Color.Red). However, no matter what it is in that field, the text for that label is always displaying black. I have even made sure that the user control's ForeColor is not black (which should not matter, but I gave it a try with a "Me.ForeColor = lDateTime.ForeColor" right before the show statement anyway). The BackColor is being shown properly and responding to changes properly using the exact same technique. Anyone have any ideas what might be going on.
However, I am having a problem with my solution with the forecolor. I have an exposed property:
Public Property Sub DisabledForeColor
Get
Return lDateTime.ForeColor
End Get
Set (Value As Color)
lDateTime.ForeColor = Value
End Set
End Property
This seems to work properly. If I change this property and I examine lDateTimeLabel.ForeColor in a debugger, I can see that it has the correct value. The core of what I want to do is done by overriding the OnEnabledChange method:
Protected Overrides Sub OnEnabledChanged(ByVal e As System.EventArgs)
If Enabled() Then
dtDateTimePicker.Enabled = True
dtDateTimePicker.Show()
lDateTime.Hide()
Else
dtDateTimePicker.Enabled = False
dtDateTimePicker.Hide()
lDateTime.Show()
End If
MyBase.OnEnabledChanged(e)
End Sub
Again, when I examine lDateTime.ForeColor in the debugger right before Show is called, it has the correct value (I have experimented with Color.White and Color.Red). However, no matter what it is in that field, the text for that label is always displaying black. I have even made sure that the user control's ForeColor is not black (which should not matter, but I gave it a try with a "Me.ForeColor = lDateTime.ForeColor" right before the show statement anyway). The BackColor is being shown properly and responding to changes properly using the exact same technique. Anyone have any ideas what might be going on.