Hi,
Can you please check below code and provide me a fix when add minutes buttons pressed, add the minutes in AddminutesTextBox to the TimerLabel
Thanks
Imports System.IO
Imports System.Threading
Public Class Form1
Private countdownTimer As Timer
Private countdownMinutes As Integer
Private countdownSeconds As Integer
Public Sub New()
InitializeComponent()
' Set the form size, title, and icon
'Me.Size = New Size(1000, 1000)
Me.WindowState = FormWindowState.Maximized
' Me.FormBorderStyle = FormBorderStyle.None
' LogoPictureBox.Location = New Point((Me.ClientSize.Width - LogoPictureBox.Width) / 2, 0)
LogoPictureBox.Anchor = AnchorStyles.Top Or AnchorStyles.Left
LogoPictureBox.Dock = DockStyle.None
Me.Text = "Countdown Timer"
'Me.Icon = My.Resources.TimerIcon
' Customize the Start button
'PauseButton.Text = "START"
PauseButton.Font = New Font("Segoe UI", 12, FontStyle.Bold)
PauseButton.BackColor = Color.FromArgb(0, 123, 255)
PauseButton.ForeColor = Color.White
' Customize the Stop button
'StopButton.Text = "STOP"
StopButton.Font = New Font("Segoe UI", 12, FontStyle.Bold)
StopButton.BackColor = Color.Red
StopButton.ForeColor = Color.White
' Customize the Countdown TextBox and set its size
AddminutesTextBox.Font = New Font("Segoe UI", 20)
AddminutesTextBox.TextAlign = HorizontalAlignment.Center
AddminutesTextBox.Size = New Size(100, 80)
Label1.Size = New Size(180, 80)
' Customize the Timer Label
TimerLabel.Font = New Font("Segoe UI", 100, FontStyle.Bold)
TimerLabel.ForeColor = Color.FromArgb(0, 123, 255)
' Customize the Timer Label for digital clock display
'TimerLabel.Font = New Font("Digital-7", 100, FontStyle.Bold) ' need to install this font
'TimerLabel.ForeColor = Color.FromArgb(0, 123, 255)
' Customize the Menu Strip
MenuStrip.BackColor = Color.FromArgb(0, 123, 255)
MenuStrip.ForeColor = Color.White
' Customize the Status Strip
StatusStrip.BackColor = Color.FromArgb(0, 123, 255)
StatusStrip.ForeColor = Color.White
' Customize the LogoPictureBox
LogoPictureBox.SizeMode = PictureBoxSizeMode.Zoom
LogoPictureBox.BackColor = Color.White
' LogoPictureBox.Image = My.Resources.LogoImage ' Replace with logo image
PauseButton.Enabled = True
StopButton.Enabled = True
PauseButton.Enabled = True
' Get the path to the application's folder and construct the icon file path
Dim appPath As String = Application.StartupPath
Dim iconPath As String = IO.Path.Combine(appPath, "AppIcon.ico")
' Check if the icon file exists and set it as the form's icon
If IO.File.Exists(iconPath) Then
Me.Icon = New Icon(iconPath)
End If
End Sub
Private Sub TimerTick(state As Object)
If countdownSeconds > 0 Then
countdownSeconds -= 1
UpdateTimerDisplay()
Else
countdownSeconds -= 1
UpdateTimerDisplay()
TimerLabel.ForeColor = Color.Red
'countdownTimer.Dispose() ' Stop the timer
'MessageBox.Show("Time reached!", "Countdown Complete", MessageBoxButtons.OK, MessageBoxIcon.Information)
'AddminutesTextBox.Enabled = True
' PauseButton.Enabled = True
' StopButton.Enabled = False
' PauseButton.Enabled = False
'AddminutesTextBox.Text = ""
End If
End Sub
Private Sub UpdateTimerDisplay()
Dim minutes As Integer = countdownSeconds \ 60
Dim seconds As Integer = countdownSeconds Mod 60
TimerLabel.Invoke(Sub() TimerLabel.Text = $"{minutes:00}:{seconds:00}")
End Sub
' Menu Strip Event Handlers
Private Sub FileExitMenuItem_Click(sender As Object, e As EventArgs)
Close()
End Sub
' Status Bar Event Handlers
Private Sub AboutMenuItem_Click(sender As Object, e As EventArgs)
MessageBox.Show("Countdown Timer App", "About", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
' Logo
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TimerLabel.Text = "00:00" ' Reset the timer label
' Get the current directory where the application is running
Dim appPath As String = Application.StartupPath
' Construct the full path to the logo image
Dim logoPath As String = Path.Combine(appPath, "Logo.jpg") ' Replace "Logo.jpg" with the image file name
' Check if the logo image file exists
If File.Exists(logoPath) Then
' Load and set the application logo
Dim logoImage As Image = Image.FromFile(logoPath)
LogoPictureBox.Image = logoImage
Else
' Handle the case where the logo image file is not found
MessageBox.Show("Logo image not found in the application folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
' Handle the Stop button click event to stop and reset the countdown
countdownTimer.Dispose() ' Stop the timer
TimerLabel.Text = "00:00" ' Reset the timer label
' Enable the Start button and disable the Stop button
' CountdownTextBox.Enabled = True
'CountdownTextBox.Text = ""
PauseButton.Enabled = True
StopButton.Enabled = True
End Sub
Private Sub ApplicantButton_Click(sender As Object, e As EventArgs) Handles ApplicantButton.Click
Dim minutes As Integer = 5
If Integer.TryParse(minutes, countdownMinutes) Then
countdownSeconds = countdownMinutes * 60
'CountdownTextBox.Enabled = False
PauseButton.Enabled = True
StopButton.Enabled = True
ApplicantButton.Enabled = False
' Start the countdown timer
countdownTimer = New Timer(AddressOf TimerTick, Nothing, 0, 1000)
Else
MessageBox.Show("Please enter a valid number of minutes.", "Countdown Timer", MessageBoxButtons.OK, MessageBoxIcon.Error)
'CountdownTextBox.Text = ""
End If
End Sub
Private Sub PauseButton_Click(sender As Object, e As EventArgs) Handles PauseButton.Click
countdownTimer.Dispose()
End Sub
Private Sub AddMinutesbutton_Click(sender As Object, e As EventArgs) Handles AddMinutesbutton.Click
Dim additionalMinutes As Integer
If Integer.TryParse(AddminutesTextBox.Text, additionalMinutes) Then
countdownMinutes += additionalMinutes
UpdateTimerDisplay()
Else
MessageBox.Show("Please enter a valid number of minutes to add.", "Countdown Timer", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Private Sub UpdateCountdownLabel()
TimerLabel.Text = countdownMinutes.ToString("00") & ":" & countdownSeconds.ToString("00")
End Sub
Public Sub New(ByVal minutes As Integer)
InitializeComponent()
countdownMinutes = minutes
countdownSeconds = 0
End Sub
Private Sub Objector1Button_Click(sender As Object, e As EventArgs) Handles Objector1Button.Click
Dim minutes As Integer = 5
If Integer.TryParse(minutes, countdownMinutes) Then
countdownSeconds = countdownMinutes * 60
'CountdownTextBox.Enabled = False
PauseButton.Enabled = True
StopButton.Enabled = True
ApplicantButton.Enabled = False
' Start the countdown timer
countdownTimer = New Timer(AddressOf TimerTick, Nothing, 0, 1000)
Else
MessageBox.Show("Please enter a valid number of minutes.", "Countdown Timer", MessageBoxButtons.OK, MessageBoxIcon.Error)
'CountdownTextBox.Text = ""
End If
End Sub
Private Sub Objector2Button_Click(sender As Object, e As EventArgs) Handles Objector2Button.Click
Dim minutes As Integer = 2.3
If Integer.TryParse(minutes, countdownMinutes) Then
countdownSeconds = countdownMinutes * 60
'CountdownTextBox.Enabled = False
PauseButton.Enabled = True
StopButton.Enabled = True
ApplicantButton.Enabled = False
' Start the countdown timer
countdownTimer = New Timer(AddressOf TimerTick, Nothing, 0, 1000)
Else
MessageBox.Show("Please enter a valid number of minutes.", "Countdown Timer", MessageBoxButtons.OK, MessageBoxIcon.Error)
'CountdownTextBox.Text = ""
End If
End Sub
End Class