''' <summary>設定した時間になったことをお知らせします。</summary> Public Class DateTimer Inherits System.ComponentModel.Component Protected Timer As New Timers.Timer(50.0R) ''' <param name="SetingDateTime">設定時刻を指定します。</param> Public Sub New(ByVal SetingDateTime As Date) AddHandler Timer.Elapsed, AddressOf TimeCheck Me.SettingDateTime = SetingDateTime Timer.Enabled = True End Sub ''' <summary>設定した時間になった時に発生します。</summary> ''' <param name="Enabled">時間になった時にEnabledプロパティを変更できるように参照型でプロパティを送ります。</param> Public Event ItWasTime(ByVal sender As Object, ByVal e As EventArgs, ByRef Enabled As Boolean) Dim _settingDateTime As Date ''' <summary>設定時刻を指定します。</summary> Public Property SettingDateTime() As Date Get Return _settingDateTime End Get Set(ByVal value As Date) _settingDateTime = value End Set End Property Protected Overridable Sub TimeCheck(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs) If Now >= SettingDateTime Then Me.Enabled = False OnItWasTime(New EventArgs) End If End Sub Protected Overrides Sub Dispose(ByVal disposing As Boolean) RemoveHandler Timer.Elapsed, AddressOf TimeCheck MyBase.Dispose(disposing) End Sub Protected Overridable Sub OnItWasTime(ByVal e As EventArgs) RaiseEvent ItWasTime(Me, e, Me.Enabled) End Sub Protected Overrides Sub Finalize() RemoveHandler Timer.Elapsed, AddressOf TimeCheck MyBase.Finalize() End Sub Public Property Enabled() As Boolean Get Return Timer.Enabled End Get Set(ByVal value As Boolean) Timer.Enabled = value End Set End Property End Class