Timer.tick within 1 min back-forth - vb.net

I have 2 Form and i want it to be slide show back & forth within 1 minute.
Please write down the code thank you!
My Code:
Form 1
Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles BunifuCheckbox1.OnChange
If BunifuCheckbox1.Checked Then
tmrSLIDE.Enabled = True
tmrSLIDE.Start()
Else
tmrSLIDE.Stop()
End If
End Sub
Private Sub tmrSLIDE_Tick(sender As Object, e As EventArgs) Handles tmrSLIDE.Tick
trs1.ShowSync(Form2)
Me.Hide()
End Sub
Form 2:
Private Sub BunifuCheckbox1_OnChange(sender As Object, e As EventArgs) Handles BunifuCheckbox1.OnChange
If BunifuCheckbox1.Checked Then
tmrSLIDE2.Enabled = True
tmrSLIDE2.Start()
Else
tmrSLIDE2.Stop()
End If
End Sub
Private Sub tmrSLIDE_Tick(sender As Object, e As EventArgs) Handles tmrSLIDE2.Tick
trs2.ShowSync(Form1)
Me.Hide()
End Sub
Property tmrSLIDE interval = 60000
property tmrSLIDE2 interval = 120000
I just Want to have 1 Checkbox with a simplified code thank you!

Related

StopWatch and Timer Accuracy

I'm using the following code to control a label to output a stopwatch. The buttons work, and the label is outputting the information mostly correctly, however it only update every so often and i would like for the label to update the information every millisecond.
Private SW As New Stopwatch
Dim timercount As Integer = 1 'The number of seconds
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SW.Start()
Timer1.Start()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Timer1.Enabled = False 'Stop the timer
timercount = 0 'Reset to 0 seconds
Label10.Text = "00:00:00.000"
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim ts As TimeSpan = SW.Elapsed
Label10.Text = ts.ToString("hh\:mm\:ss\.fff")
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Timer1.enabled = False
End Sub
Any help is much appreciated.
You can set the timer to a reasonable value, say 20 times a second, to rapidly display it changing.
You can create the timer and stopwatch in code, which I think is easier than adding a control to the form—you can see right there in the code what is being programmed. I used sensible names for the buttons so that you can tell what is meant to do what.
If you keep the sub to display the data separate from the code that processes the data, it is easy to change the display in just one place, in case someone decided they wanted it written as words, for example, or maybe the hours in a separate box, or something.
Public Class Form1
Dim sw As New Stopwatch
Dim tim As Timer
Private Sub ShowElapsedTime()
lblTime.Text = sw.Elapsed.ToString("hh\:mm\:ss\.fff")
End Sub
Private Sub bnStart_Click(sender As Object, e As EventArgs) Handles bnStart.Click
sw.Restart()
tim.Enabled = True
End Sub
Private Sub bnStop_Click(sender As Object, e As EventArgs) Handles bnStop.Click
sw.Stop()
tim.Enabled = False
ShowElapsedTime()
End Sub
Private Sub bnReset_Click(sender As Object, e As EventArgs) Handles bnReset.Click
tim.Enabled = False
sw.Reset()
ShowElapsedTime()
End Sub
Private Sub tim_Tick(sender As Object, e As EventArgs)
ShowElapsedTime()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
tim = New Timer With {.Interval = 50}
AddHandler tim.Tick, AddressOf tim_Tick
ShowElapsedTime()
End Sub
End Class

How can I make a button move up in size (by going vertically up), but not in total size?

I'm having a slight conflict with a button which I've been working with in Visual Basic NET.
My first code sample is for my Button_Height_Tick, which controls changing the button's height:
Dim ChangeHeight As Boolean = False
Private Sub Button_Height_Tick(sender As Object, e As EventArgs) Handles Button_Height.Tick
If Not ChangeHeight Then
Do Until FlatButton1.Height = 63
FlatButton1.Height += 1
System.Threading.Thread.Sleep(1)
Loop
ChangeHeight = True
Else
End If
End Sub
And for my FlatButton1_MouseHover.
Private Sub FlatButton1_MouseHover(sender As Object, e As EventArgs) Handles FlatButton1.MouseHover
Button_Height.Enabled = True
Button_Height.Start()
End Sub
Now, as you can see in the Button_Height_Tick sub, the code changes the height of the button to 63, however, when this code is ran, the buttons total height is changed.
Here are some photos in-case I haven't explained it well.
What my original button looks like
What I want it to do
What it's doing (going up in size vertically going down, when I want it to go up)
Please comment below if you don't understand this question.
You need to change the 'Top' position and also I notice you have a timer then just go in a do a loop. In your example there's no need for a timer.
I'll give an example using a timer and hopefully you'll understand it and can use it for what you want. I've changed 'hover' to 'enter' and 'leave'.
If it's too slow just change the increment amount.
Dim ChangeHeight As Boolean = False
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ChangeHeight Then
FlatButton1.Height += 2
FlatButton1.Top -= 2
If FlatButton1.Height < 63 Then Exit Sub
FlatButton1.Height = 63
Timer1.Enabled = False
Else
FlatButton1.Height -= 2
FlatButton1.Top += 2
If FlatButton1.Height > 31 Then Exit Sub
FlatButton1.Height = 31
Timer1.Enabled = False
End If
End Sub
Private Sub FlatButton1_MouseEnter(sender As Object, e As EventArgs) Handles FlatButton1.MouseEnter
ChangeHeight = True
If Timer1.Enabled Then Exit Sub
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub FlatButton1_MouseLeave(sender As Object, e As EventArgs) Handles FlatButton1.MouseLeave
ChangeHeight = False
If Timer1.Enabled Then Exit Sub
Timer1.Enabled = True
Timer1.Start()
End Sub
Hello and welcome to StackOverflow. I did a little example of how to achieve what you are looking for.
Code:
Public Class Form1
Dim buttonXCoordinate As Integer
Dim buttonYCoordinate As Integer
Dim buttonOriginalHeight As Integer
Dim buttonOriginalLocation As Point
Private Sub GetButtonCoordinate()
buttonXCoordinate = testBtn.Left
buttonYCoordinate = testBtn.Top
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buttonOriginalHeight = testBtn.Height
buttonOriginalLocation = testBtn.Location
GetButtonCoordinate()
End Sub
Private Sub testBtn_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles testBtn.MouseEnter
Dim buttonLocation As Point = Nothing
GetButtonCoordinate()
buttonLocation.X += buttonXCoordinate
buttonLocation.Y += buttonYCoordinate - buttonOriginalHeight
testBtn.Height += buttonOriginalHeight
testBtn.Location = buttonLocation
End Sub
Private Sub testBtn_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles testBtn.MouseLeave
testBtn.Height = buttonOriginalHeight
testBtn.Location = buttonOriginalLocation
End Sub
End Class
I did it really fast but it's enough to give you an idea to how to achive your goal.
In my example there is a button called testBtn, when you go over it with the mouse it the button's height is increased and it returns back to normal when you move your mouse out of it

Enable a counter at a specific time everyday

I setup a counter which needs to be enabled at specific time everyday. for an example lets say at (3 PM) everyday. what i came up with is following piece of code. but it gives me an error when it reach the time saying parameter is not valid please help me,
Private t As Integer = 0
Private Sub Home_monitoring_tab_Load(sender As Object, e As EventArgs) Handles MyBase.Load
rs.FindAllControls(Me)
Execute()
End Sub
Private Sub Execute()
If DateTime.Now.ToString("HH:mm") = "15:00" Then
shift1_timer.Enabled = True
End If
End Sub
Private Sub shift1_timer_Tick(sender As Object, e As EventArgs) Handles shift1_timer.Tick
t += 1
Label14.Text = CStr(t)
End Sub
Try this, add a timer to your program and call it CheckTimer and update your code like this :
Private t As Integer = 0
Private Sub Home_monitoring_tab_Load(sender As Object, e As EventArgs) Handles MyBase.Load
rs.FindAllControls(Me)
CheckTimer.Interval = 1
CheckTimer.Start
End Sub
Private Sub CheckTimer_Tick(sender As Object, e As EventArgs) Handles CheckTimer.Tick
If DateTime.Now.ToString("HH:mm") = "15:00" Then
shift1_timer.Enabled = True
End If
End Sub
Private Sub shift1_timer_Tick(sender As Object, e As EventArgs) Handles shift1_timer.Tick
t += 1
Label14.Text = CStr(t)
End Sub
Hope it helped :)

Covering Panel with another

Private Sub frmitem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pnldeposit.Visible = False
pnlwithdraw.Visible = False
End Sub
Private Sub cmdideposit_Click(sender As Object, e As EventArgs) Handles cmdideposit.Click
pnldeposit.Visible = True
pnlwithdraw.Visible = False
End Sub
Private Sub cmdiwithdraw_Click(sender As Object, e As EventArgs) Handles cmdiwithdraw.Click
pnlwithdraw.Visible = True
pnldeposit.Visible = False
End Sub
//i am having problem with this form. i want to show the first panel which is successful, but the problem is showing the second panel. it is not working, im using buttons btw. help me. Thank you in advance :D
Here is a quick example using BringToFront. With both panels having the same Location and being the same Size.
Public Class Form1
Private switchPanels As Boolean
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
switchPanels = Not switchPanels
If switchPanels Then
Panel1.BringToFront()
Else
Panel2.BringToFront()
End If
End Sub
End Class
Private Sub cmdideposit_Click(sender As Object, e As EventArgs) Handles cmdideposit.Click
pnldeposit.Visible = True
pnlwithdraw.Visible = False
pnlreport.Visible = False
End Sub
Private Sub cmddcancel_Click(sender As Object, e As EventArgs)
pnldeposit.Hide()
End Sub
Private Sub cmdiwithdraw_Click(sender As Object, e As EventArgs) Handles cmdiwithdraw.Click
pnlwithdraw.Visible = True
pnlreport.Visible = False
End Sub
Private Sub cmdwclear_Click(sender As Object, e As EventArgs) Handles cmdwclear.Click
pnlwithdraw.Visible = False
End Sub
Private Sub cmdireport_Click(sender As Object, e As EventArgs) Handles cmdireport.Click
pnlreport.Visible = True
End Sub
//thank you for sharing your idea! i found how it works. thanks! :D

My progress bar goes over its specified amount

I created a simple program called poodle doodle where you just click buttons to add to a progress bar but they could easily crash the program by just going 1 over the max amount but i cant figure out how to stop it from doing that. How can I?
Here's my current code
Public Class Form1
Private Sub poodle_Click(sender As Object, e As EventArgs) Handles poodle.Click
doodle.Visible = True
poodle.Visible = False
pdb1.Value = pdb1.Value + 1
End Sub
Private Sub doodle_Click(sender As Object, e As EventArgs) Handles doodle.Click
poodle.Visible = True
doodle.Visible = False
End Sub
Private Sub pdb1_Click(sender As Object, e As EventArgs) Handles pdb1.Click
If pdb1.Value = 100 Then
MessageBox.Show("You Poddled And Doodled To Victory!", "Poodle Doodle Champion")
pdb1.Value = pdb1.Value = 0
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
pdb1.Maximum = TextBox1.Text
End Sub
Change the poodle_Click method to check that the value is less than 100 like this:
Private Sub poodle_Click(sender As Object, e As EventArgs) Handles poodle.Click
doodle.Visible = True
poodle.Visible = False
' This bit
If pdb1.Value < 100 Then
pdb1.Value += 1
End If
End Sub
You'll probably want to add other logic to disable the poodle/doodle buttons when the player wins and a way to restart the game.
I'm not sure why you put pdb1.Value = pdb1.Value = 0 in the pdb1_Click method, it should just be pdb1.Value = 0.