I created a custom control called TimePicker which inherits from the DateTimePicker. The only difference between my TimePicker and the regular DateTimePicker is that the CustomFormat property is set to show time ("h:mm tt"). The reason why I created this custom control is so that if at some future time, I decide to change the custom format to something else, I would only have to change it in one place, my custom control. 

However, there is a big problem. Whenever I drag and drop my custom control onto the design surface of a Windows Form, the Windows Designer generated code inserts code containing the value for the CustomFormat property: 


'TimePicker1 

Me.TimePicker1.CustomFormat = "h:mm tt" 
Me.TimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom 

This is a big problem because if I change the value in my custom control, none of the existing forms will be updated to the use the new value! (Instead, they'll use the value in the Windows Forms Designer generated code.) 

I tried using the DefaultValue attribute, however, this seems to have no effect. 

Here is the code for my custom control: 

Option Strict On 

Imports System.ComponentModel 

Public Class TimePicker 
  Inherits DateTimePicker 

  Private Const DEFAULT_CUSTOM_FORMAT As String = "h:mm tt" 
  Private Const DEFAULT_FORMAT As DateTimePickerFormat = DateTimePickerFormat.Custom 

  Public Sub New() 
    MyBase.Format = DEFAULT_FORMAT 
    MyBase.CustomFormat = DEFAULT_CUSTOM_FORMAT 
    MyBase.ShowUpDown = True 
    MyBase.Size = New System.Drawing.Size(96, 20) 
  End Sub 

  < _ 
  Category("Behavior"), _ 
  DefaultValue(DEFAULT_CUSTOM_FORMAT), _ 
  Description("The custom format string used to format the date and/or time displayed in the control.") _ 
  > _ 
  Public Shadows Property CustomFormat() As String 
    Get 
      Return MyBase.CustomFormat 
    End Get 
    Set(ByVal Value As String) 
      MyBase.CustomFormat = Value 
    End Set 
  End Property 

  < _ 
  Category("Behavior"), _ 
  DefaultValue(DEFAULT_FORMAT), _ 
  Description("The custom format string used to format the date and/or time displayed in the control.") _ 
  > _ 
  Public Shadows Property Format() As DateTimePickerFormat 
    Get 
      Return MyBase.Format 
    End Get 
    Set(ByVal Value As DateTimePickerFormat) 
      MyBase.Format = Value 
    End Set 
  End Property 

End Class 

What am I doing wrong? Is there anything I can do to fix this?