CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    Timer Resize Label Width

    Hi, I had the following code:

    Code:
    Private Sub btnTransfer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTransfer.Click
    
    Timer1.Interval = 1000
    Timer1.Enabled = True
    Timer1.Start()
    
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Try
                Dim intStart As Integer = 0
                Dim intEnd As Integer = 120
                Dim second As Integer = 0
    
                lblDNC.Size = New System.Drawing.Size(0, 13)
    
                While intStart < intEnd
                    lblDNC.Size = New System.Drawing.Size(intStart, 13)
                    intStart += 1
                End While
    
            Catch ex As Exception
                Throw
            End Try
        End Sub

    What I want is expand label size from 0 to 120 in 5 seconds then reset the label width back to 0 and looping.

    My code doesn't works. Anyone can help?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Timer Resize Label Width

    You are basically setting intStart to 0 each time you enter the routine so your label is always going to be 0,13 in size

    You need to use a static var or a var with a higher scope. You also need to move that code out of the timer that sets the label to 0 initially or wrap it in an If clause so that it only sets it to 0 under after a given amount of ticks.

    You should probably do some reading on static, local and global variables.
    Always use [code][/code] tags when posting code.

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

Featured