|
-
Oct 16th, 2010, 02:14 PM
#1
Thread Starter
Lively Member
[RESOLVED] Align Text after certain amount (CountDown)
I have this code in Timer1:
vb Code:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Dim a As Integer Dim b As Integer a = Label2.Text b = 1 Label2.Text = a - b If Label2.Text = "-1" Then Timer1.Stop() 'Stop timer, no more numbers PictureBox2.Visible = True Timer2.Stop() 'Stop timer, ENDED 10 SECONDS Label6.ForeColor = Color.Red Label7.ForeColor = Color.Green Label2.Text = "15" 'Starting 15 seconds countdown Timer1.Start() Timer3.Start() End If End Sub
I want that if the number in the label2 (coundown) is <=9 the position will be "224, 28" else "211, 28".
I added this code in all possible locations but it didn't seem to work..
vb Code:
If Label2.Text <= 9 Then Label2.Location = New Point(224, 28) Else Label2.Location = New Point(211, 28) End If
Pictures:
Right position:

Wrong position with all numbers > 9:

Help me.
Thank you.
Last edited by Acrobater; Oct 16th, 2010 at 02:19 PM.
-
Oct 16th, 2010, 02:25 PM
#2
Re: Align Text after certain amount (CountDown)
try this:
vb Code:
Public Class Form1
Dim counter As Integer = 15
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
counter -= 1
Label1.Text = counter.ToString
Label1.Location = If(counter <= 9, New Point(224, 28), New Point(211, 28))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = counter.ToString
Label1.Location = New Point(211, 28)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 16th, 2010, 03:02 PM
#3
Thread Starter
Lively Member
Re: Align Text after certain amount (CountDown)
Thank you this code works but I have 3 timers and they need to be aligned too.
Check this code and see how it works for you and you will see what I mean:
All timers are Interval = 1000
vb Code:
Public Class DFUModeHelperII Dim counter As Integer = 3 '3 SECONDS (FIRST ONE) Dim counter1 As Integer = 10 '10 SECONDS (SECOND ONE) Dim counter2 As Integer = 15 '15 SECONDS (THIRD AND LAST ONE) Private Sub DFUModeHelperII_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label2.Text = counter.ToString '3 SECONDS Label2.Location = New Point(224, 28) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True 'BEGIN THE TIMER 3 SECONDS Button1.Enabled = False 'BUTTON DISABLED TO PREVENT RESET BEFORE THE TIMER FINISHES End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick counter -= 1 '-1 SECOND PER X Label2.Text = counter.ToString '3 SECONDS COUNTER TO STRING Label2.Location = If(counter <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS" If Label2.Text = "-1" Then Label2.Text = "10" Timer1.Enabled = False Timer2.Enabled = True End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick counter1 -= 1 '-1 SECOND PER X Label2.Text = counter1.ToString '10 SECONDS COUNTER TO STRING Label2.Location = If(counter1 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS" If Label2.Text = "-1" Then Timer2.Enabled = False Timer3.Enabled = True End If End Sub Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick counter2 -= 1 '-1 SECOND PER X Label2.Text = counter2.ToString '15 SECONDS COUNTER TO STRING Label2.Location = If(counter2 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS" If Label2.Text = "-1" Then Label2.Text = "3" Timer3.Enabled = False Button1.Enabled = True MsgBox("Congratularions" & Environment.NewLine & "You are now on DFU Mode!", "Congratulations", MessageBoxButtons.OK) End If End Sub End Class
-
Oct 17th, 2010, 08:11 AM
#4
Thread Starter
Lively Member
Re: Align Text after certain amount (CountDown)
-
Oct 18th, 2010, 09:46 AM
#5
Thread Starter
Lively Member
Re: Align Text after certain amount (CountDown)
Please someone help me.. I can't figure out how to align. Copy this code and you will see what I mean:
All timers are Interval = 1000
vb Code:
Public Class DFUModeHelperII Dim counter As Integer = 3 '3 SECONDS (FIRST ONE) Dim counter1 As Integer = 10 '10 SECONDS (SECOND ONE) Dim counter2 As Integer = 15 '15 SECONDS (THIRD AND LAST ONE) Private Sub DFUModeHelperII_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label2.Text = counter.ToString '3 SECONDS Label2.Location = New Point(224, 28) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Timer1.Enabled = True 'BEGIN THE TIMER 3 SECONDS Button1.Enabled = False 'BUTTON DISABLED TO PREVENT RESET BEFORE THE TIMER FINISHES End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick counter -= 1 '-1 SECOND PER X Label2.Text = counter.ToString '3 SECONDS COUNTER TO STRING Label2.Location = If(counter <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS" If Label2.Text = "-1" Then Label2.Text = "10" Timer1.Enabled = False Timer2.Enabled = True End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick counter1 -= 1 '-1 SECOND PER X Label2.Text = counter1.ToString '10 SECONDS COUNTER TO STRING Label2.Location = If(counter1 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS" If Label2.Text = "-1" Then Timer2.Enabled = False Timer3.Enabled = True End If End Sub Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick counter2 -= 1 '-1 SECOND PER X Label2.Text = counter2.ToString '15 SECONDS COUNTER TO STRING Label2.Location = If(counter2 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS" If Label2.Text = "-1" Then Label2.Text = "3" Timer3.Enabled = False Button1.Enabled = True MsgBox("Congratularions" & Environment.NewLine & "You are now on DFU Mode!", "Congratulations", MessageBoxButtons.OK) End If End Sub End Class
-
Oct 18th, 2010, 09:58 AM
#6
Fanatic Member
Re: Align Text after certain amount (CountDown)
Uhhh, I have a workaround. Set the "AutoSize" property of the label with the remaining second to "False", then resize it so the left border is touching the very edge of "you have", and the right edge is touching the very beginning of "remaining", then set the textAlign of the label to center. Now you shouldn't have to move the label at all, as it will place the text centered in the label.
If I helped you out, please take the time to rate me 
-
Oct 18th, 2010, 12:30 PM
#7
Thread Starter
Lively Member
Re: Align Text after certain amount (CountDown)
Thank you!!
It worked like a charm and no code needed Just setting the properties...
P.S. I don't know why but I can't give rep to you... "You must spread reputation before..."
-
Oct 18th, 2010, 07:54 PM
#8
Fanatic Member
Re: Align Text after certain amount (CountDown)
I think I helped you in a thread recently and you repped me there, so if you keep repping me it looks like favoritism Guess it's to stop people creating alternate accounts and rep spamming their main.
If I helped you out, please take the time to rate me 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|