I'm currently writing a countdown timer on vb 2005, with the following characteristics:
-When I press a button and the timer is running, it adds time to the counter, for example, if the time is 2:30 and I press a button, and the period to add is 1:10, the new time would be 4:40.
-The window is always on top of every other window, and is active even though it doesn't have focus.
-When the time's up and i press a key, in this case Esc, the application closes, otherwise, it just continues.
So far, I have all the settings and the timer, but I can't seem to get this three parts right, here's my code, if you could help me, that would be great.
Here's my code
thanks in advance
-When I press a button and the timer is running, it adds time to the counter, for example, if the time is 2:30 and I press a button, and the period to add is 1:10, the new time would be 4:40.
-The window is always on top of every other window, and is active even though it doesn't have focus.
-When the time's up and i press a key, in this case Esc, the application closes, otherwise, it just continues.
So far, I have all the settings and the timer, but I can't seem to get this three parts right, here's my code, if you could help me, that would be great.
Here's my code
VB.NET:
Public Class Form1
Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long _
) As Long
Public Const HWND_TOPMOST = -1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const swp_showwindow = &H2
Public Const swp_noactivate = &H1
Private alarmTime As Date
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Label1.Text = String.Format("press to run")
Me.CenterToScreen()
Me.TopMost = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If alarmTime < Date.Now Then
Me.Timer1.Stop()
Me.Label1.Text = String.Format("time's up")
My.Computer.Audio.Play("c:\DING.WAV")
Else
Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now)
Me.Label1.Text = String.Format("{0}:{1:d2}:{2:d2}", _
remainingTime.Hours, _
remainingTime.Minutes, _
remainingTime.Seconds)
End If
If Me.Label1.Text = String.Format("0:00:10") Then
Me.CenterToScreen()
Me.Label1.ForeColor = Color.Yellow
End If
If Me.Label1.Text = "0:00:05" Then
Me.Label1.ForeColor = Color.Red
End If
End Sub
Private Sub Button1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown
If e.KeyCode = Keys.A Then
Me.alarmTime = Date.Now.AddMinutes(0.7)
Me.Timer1.Start()
My.Computer.Audio.Play("c:\CHIMES.WAV")
Me.SetDesktopLocation(0, 745)
Me.Label1.ForeColor = Color.White
End If
If e.KeyCode = Keys.Escape Then
Me.Close()
End If
End Sub
Public Sub SetFormPosition(ByVal hWnd As Long, ByVal Position As Long)
SetWindowPos(hWnd, Position, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or swp_showwindow Or swp_noactivate)
End Sub
End Class
thanks in advance