This is my first post, so please forgive me if I am not doing this correctly.
I have the following code that sets a DateTimePicker as Readonly (and it works well). But to give the full effect of being readonly, I would like to implement the ability to change the Backcolor and disable the ability to use the calender.
Does anyone know how to change the Backcolor and disable the Calender?
Public Class ReadOnlyDTP
Inherits DateTimePicker
'This hash table stores all the controls extended by this extender provider
Friend htProvidedProperties As New Hashtable
#Region "Extensible Properties"
Private Class DateTimePickerProperties
Public IsReadOnly As Boolean = False
End Class
<Category("Read Only DateTimePicker Provider")> _
Sub SetReadOnly(ByVal ctrl As Control, ByVal value As Boolean)
Dim dtpSender As DateTimePicker = CType(ctrl, DateTimePicker)
GetControlFromHashtable(ctrl).IsReadOnly = value
End Sub
<Category("Read Only DateTimePicker Provider")> _
Function GetReadOnly(ByVal ctrl As Control) As Boolean
Return GetControlFromHashtable(ctrl).IsReadOnly
End Function
#End Region
#Region "behavior"
Private Function GetControlFromHashtable(ByVal ctrl As Control) As DateTimePickerProperties
If htProvidedProperties.Contains(ctrl) Then
Return DirectCast(htProvidedProperties(ctrl), DateTimePickerProperties)
Else
'Add Event Handlers as the control is added to hash table
AddHandler ctrl.KeyPress, AddressOf KeyPressHandler
Dim ProvidedProperties As New DateTimePickerProperties
htProvidedProperties.Add(ctrl, ProvidedProperties)
Return ProvidedProperties
End If
End Function
Private Sub KeyPressHandler(ByVal sender As Object, ByVal e As KeyPressEventArgs)
Dim dtpSender As DateTimePicker = CType(sender, DateTimePicker)
If GetControlFromHashtable(dtpSender).IsReadOnly = True Then
e.Handled = True
Else
e.Handled = False
End If
End Sub
#End Region
End Class

New Topic/Question
Reply



MultiQuote





|