home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch14 / alarm / alarmctl.ctl (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-20  |  3.6 KB  |  113 lines

  1. VERSION 5.00
  2. Begin VB.UserControl AlarmCtl 
  3.    BackStyle       =   0  'Transparent
  4.    ClientHeight    =   495
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   1800
  8.    ScaleHeight     =   495
  9.    ScaleWidth      =   1800
  10.    Begin VB.Timer Timer1 
  11.       Enabled         =   0   'False
  12.       Interval        =   1000
  13.       Left            =   825
  14.       Top             =   45
  15.    End
  16.    Begin VB.Label Label1 
  17.       Alignment       =   2  'Center
  18.       BackColor       =   &H00000080&
  19.       BorderStyle     =   1  'Fixed Single
  20.       Caption         =   "00:00:00"
  21.       BeginProperty Font 
  22.          Name            =   "Tahoma"
  23.          Size            =   14.25
  24.          Charset         =   0
  25.          Weight          =   400
  26.          Underline       =   0   'False
  27.          Italic          =   0   'False
  28.          Strikethrough   =   0   'False
  29.       EndProperty
  30.       ForeColor       =   &H0000FFFF&
  31.       Height          =   480
  32.       Left            =   0
  33.       TabIndex        =   0
  34.       Top             =   0
  35.       Width           =   1800
  36.    End
  37. Attribute VB_Name = "AlarmCtl"
  38. Attribute VB_GlobalNameSpace = False
  39. Attribute VB_Creatable = True
  40. Attribute VB_PredeclaredId = False
  41. Attribute VB_Exposed = True
  42. Option Explicit
  43. Private startTime As Date
  44. Private Running As Boolean
  45. Private m_CountDown As Boolean
  46. Private m_AlarmTime As Date
  47. Event TimeOut()
  48. Private Sub Label1_Click()
  49. End Sub
  50. Private Sub Timer1_Timer()
  51.     If m_CountDown Then
  52.         If Time - m_AlarmTime > 0 Then
  53.             Label1.Caption = "00:00:00"
  54.             'MsgBox "Time Out!"
  55.             RaiseEvent TimeOut
  56.             Timer1.Enabled = False
  57.         Else
  58.             Label1.Caption = Format$(Hour(m_AlarmTime - Time) & ":" & Minute(m_AlarmTime - Time) & ":" & Second(m_AlarmTime - Time), "hh:mm:ss")
  59.         End If
  60.     Else
  61.         If Time - m_AlarmTime > 0 Then
  62.             Label1.Caption = "00:00:00"
  63.             'MsgBox "Time Out!"
  64.             RaiseEvent TimeOut
  65.             Timer1.Enabled = False
  66.         Else
  67.             Label1.Caption = Format$(Hour(Time - startTime) & ":" & Minute(Time - startTime) & ":" & Second(Time - startTime), "hh:mm:ss")
  68.         End If
  69.     End If
  70. End Sub
  71. Public Property Get CountDown() As Boolean
  72.     CountDown = m_CountDown
  73. End Property
  74. Public Property Let CountDown(ByVal vNewValue As Boolean)
  75.     m_CountDown = vNewValue
  76. End Property
  77. Public Sub StartTimer()
  78.     If Not Running Then
  79.         Timer1.Enabled = True
  80.         Running = True
  81.         startTime = Time
  82.         Label1.Caption = "00:00.00"
  83.     End If
  84. End Sub
  85. Public Sub StopTimer()
  86.     If Running Then
  87.         Timer1.Enabled = False
  88.         Running = False
  89.     End If
  90. End Sub
  91. Private Sub UserControl_InitProperties()
  92.     m_CountDown = True
  93.     Running = False
  94. End Sub
  95. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  96.     CountDown = PropBag.ReadProperty("countdown", CountDown)
  97.     m_AlarmTime = PropBag.ReadProperty("AlarmTime", AlarmTime)
  98. End Sub
  99. Private Sub UserControl_Resize()
  100.     UserControl.Size 1800, 500
  101.         
  102. End Sub
  103. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  104.     PropBag.WriteProperty "CountDown", m_CountDown, False
  105.     PropBag.WriteProperty "AlarmTime", m_AlarmTime, 0
  106. End Sub
  107. Public Property Get AlarmTime() As Date
  108.     AlarmTime = m_AlarmTime
  109. End Property
  110. Public Property Let AlarmTime(ByVal vNewValue As Date)
  111.     If IsDate(vNewValue) Then m_AlarmTime = vNewValue
  112. End Property
  113.