Results 1 to 8 of 8

Thread: [RESOLVED] Align Text after certain amount (CountDown)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Posts
    101

    Resolved [RESOLVED] Align Text after certain amount (CountDown)

    I have this code in Timer1:
    vb Code:
    1. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    2.         Dim a As Integer
    3.         Dim b As Integer
    4.         a = Label2.Text
    5.         b = 1
    6.         Label2.Text = a - b
    7.         If Label2.Text = "-1" Then
    8.             Timer1.Stop() 'Stop timer, no more numbers
    9.             PictureBox2.Visible = True
    10.             Timer2.Stop() 'Stop timer, ENDED 10 SECONDS
    11.             Label6.ForeColor = Color.Red
    12.             Label7.ForeColor = Color.Green
    13.             Label2.Text = "15" 'Starting 15 seconds countdown
    14.             Timer1.Start()
    15.             Timer3.Start()
    16.         End If
    17.     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:
    1. If Label2.Text <= 9 Then
    2.                 Label2.Location = New Point(224, 28)
    3.             Else
    4.                 Label2.Location = New Point(211, 28)
    5.             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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Align Text after certain amount (CountDown)

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim counter As Integer = 15
    4.  
    5.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    6.         counter -= 1
    7.         Label1.Text = counter.ToString
    8.         Label1.Location = If(counter <= 9, New Point(224, 28), New Point(211, 28))
    9.     End Sub
    10.  
    11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    12.         Label1.Text = counter.ToString
    13.         Label1.Location = New Point(211, 28)
    14.     End Sub
    15.  
    16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    17.         Timer1.Interval = 1000
    18.         Timer1.Enabled = True
    19.     End Sub
    20. End Class

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Posts
    101

    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:
    1. Public Class DFUModeHelperII
    2.  
    3.     Dim counter As Integer = 3 '3 SECONDS (FIRST ONE)
    4.     Dim counter1 As Integer = 10 '10 SECONDS (SECOND ONE)
    5.     Dim counter2 As Integer = 15 '15 SECONDS (THIRD AND LAST ONE)
    6.  
    7.  
    8.     Private Sub DFUModeHelperII_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9.         Label2.Text = counter.ToString '3 SECONDS
    10.         Label2.Location = New Point(224, 28)
    11.     End Sub
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Timer1.Enabled = True 'BEGIN THE TIMER 3 SECONDS
    15.         Button1.Enabled = False 'BUTTON DISABLED TO PREVENT RESET BEFORE THE TIMER FINISHES
    16.     End Sub
    17.  
    18.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    19.         counter -= 1 '-1 SECOND PER X
    20.         Label2.Text = counter.ToString '3 SECONDS COUNTER TO STRING
    21.         Label2.Location = If(counter <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS"
    22.         If Label2.Text = "-1" Then
    23.             Label2.Text = "10"
    24.             Timer1.Enabled = False
    25.             Timer2.Enabled = True
    26.         End If
    27.     End Sub
    28.  
    29.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    30.         counter1 -= 1 '-1 SECOND PER X
    31.         Label2.Text = counter1.ToString '10 SECONDS COUNTER TO STRING
    32.         Label2.Location = If(counter1 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS"
    33.         If Label2.Text = "-1" Then
    34.             Timer2.Enabled = False
    35.             Timer3.Enabled = True
    36.         End If
    37.     End Sub
    38.  
    39.     Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    40.         counter2 -= 1 '-1 SECOND PER X
    41.         Label2.Text = counter2.ToString '15 SECONDS COUNTER TO STRING
    42.         Label2.Location = If(counter2 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS"
    43.         If Label2.Text = "-1" Then
    44.             Label2.Text = "3"
    45.             Timer3.Enabled = False
    46.             Button1.Enabled = True
    47.             MsgBox("Congratularions" & Environment.NewLine & "You are now on DFU Mode!", "Congratulations", MessageBoxButtons.OK)
    48.         End If
    49.     End Sub
    50. End Class

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Posts
    101

    Re: Align Text after certain amount (CountDown)

    Help please.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Posts
    101

    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:
    1. Public Class DFUModeHelperII
    2.  
    3.     Dim counter As Integer = 3 '3 SECONDS (FIRST ONE)
    4.     Dim counter1 As Integer = 10 '10 SECONDS (SECOND ONE)
    5.     Dim counter2 As Integer = 15 '15 SECONDS (THIRD AND LAST ONE)
    6.  
    7.  
    8.     Private Sub DFUModeHelperII_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9.         Label2.Text = counter.ToString '3 SECONDS
    10.         Label2.Location = New Point(224, 28)
    11.     End Sub
    12.  
    13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    14.         Timer1.Enabled = True 'BEGIN THE TIMER 3 SECONDS
    15.         Button1.Enabled = False 'BUTTON DISABLED TO PREVENT RESET BEFORE THE TIMER FINISHES
    16.     End Sub
    17.  
    18.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    19.         counter -= 1 '-1 SECOND PER X
    20.         Label2.Text = counter.ToString '3 SECONDS COUNTER TO STRING
    21.         Label2.Location = If(counter <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS"
    22.         If Label2.Text = "-1" Then
    23.             Label2.Text = "10"
    24.             Timer1.Enabled = False
    25.             Timer2.Enabled = True
    26.         End If
    27.     End Sub
    28.  
    29.     Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    30.         counter1 -= 1 '-1 SECOND PER X
    31.         Label2.Text = counter1.ToString '10 SECONDS COUNTER TO STRING
    32.         Label2.Location = If(counter1 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS"
    33.         If Label2.Text = "-1" Then
    34.             Timer2.Enabled = False
    35.             Timer3.Enabled = True
    36.         End If
    37.     End Sub
    38.  
    39.     Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    40.         counter2 -= 1 '-1 SECOND PER X
    41.         Label2.Text = counter2.ToString '15 SECONDS COUNTER TO STRING
    42.         Label2.Location = If(counter2 <= 9, New Point(224, 28), New Point(211, 28)) 'ALIGN CENTER OF "SECONDS"
    43.         If Label2.Text = "-1" Then
    44.             Label2.Text = "3"
    45.             Timer3.Enabled = False
    46.             Button1.Enabled = True
    47.             MsgBox("Congratularions" & Environment.NewLine & "You are now on DFU Mode!", "Congratulations", MessageBoxButtons.OK)
    48.         End If
    49.     End Sub
    50. End Class

  6. #6
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2010
    Posts
    101

    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..."

  8. #8
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    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
  •  



Click Here to Expand Forum to Full Width