Results 1 to 14 of 14

Thread: How to make a label move

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    How to make a label move

    I've read on a few topics abt this in this forum and i have try the source code that have been suggested. Unfortunately it did not work on my project and i do not know why.
    [CODE]
    Private sub form_load()

    ndName = txbFullName
    lblUser.Caption = "You are now login as " & ndName

    end sub

    Private Sub Timer1_Timer()
    lblUser.Move lblUser.Left + 1
    End Sub[CODE]

  2. #2
    Addicted Member _RaJ_'s Avatar
    Join Date
    Apr 2008
    Location
    India!
    Posts
    198

    Re: How to make a label move

    vb Code:
    1. Private Sub ChangePosition_Click()
    2. Label1.Left = Label1.Left + 100 ' or just place ur own value like label1.left = 500
    3. Label1.Top = Label1.Top + 100 ' or just place ur own value like label1.top = 500
    4. End Sub

    that will do the work !!

    ●════════════════════════════◄►═════════════════════════●
    ___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
    ●════════════════════════════◄►═════════════════════════●
    гαj

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    Re: How to make a label move

    yeah the label moved but after we press the button can the label scroll vertically itself without stopping when the form load

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to make a label move

    Is this what you mean?
    Code:
    Private Sub Timer1_Timer()            
    Label1.Caption = ScrollText(Label1.Caption)
    End Sub
    
    Private Function ScrollText(MyText As String) As String
    'Take the first char of a string and move it to the back.
    MyText = (Right$(MyText, Len(MyText) - 1)) & Left$(MyText, 1)
    ScrollText = MyText
    End Function

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    Re: How to make a label move

    are we did not call timer in sub form_load?

  6. #6
    Addicted Member _RaJ_'s Avatar
    Join Date
    Apr 2008
    Location
    India!
    Posts
    198

    Re: How to make a label move

    do u mean to move.......... from Title.............. ??

    ●════════════════════════════◄►═════════════════════════●
    ___itš bεttεг tΘ bε απ Θρεπ šiππεг, thαπ α ƒαlšε šαiπt___
    ●════════════════════════════◄►═════════════════════════●
    гαj

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    Re: How to make a label move

    No, no sorry for make this problem complicated but what i want is the label is moving vertically when the form is loaded i have try those source code posted by Hack but it still not working.

  8. #8
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: How to make a label move

    Have you placed a timer control onto your form, is it enabled (can be set via the properties window) and what's it's interval set to (again found under the properties window).

    A control can be placed using-
    Code:
    ControlName.Left= ControlName.left -10 ' will move 10 pixels to the left.
    ControlName.Left= ControlName.left +10 ' will move 10 pixels to the right.
    ControlName.Top = ControlName.Top -10  ' will move 10 pixels upward.
    ControlName.Top = ControlName.Top +10  ' will move 10 pixels downward.
    You can test these codes in a button's click event on your form. Placing this into a timer means whenever the timer interval is encountered (i.e. every 100 nanoseconds if it's interval is set to 100), this code will run and say, move the control left. If the timer interval is set low enough, the movement line of code will happen rappidly in succession and give the appearance of the control being animated.
    Last edited by alex_read; Jun 18th, 2008 at 01:18 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to make a label move

    Quote Originally Posted by hiadan_dan
    are we did not call timer in sub form_load?
    If the timer is enabled, it will begin as soon as the Form is Loaded. You don't have to have any code to activate it.
    Quote Originally Posted by hiadan_dan
    No, no sorry for make this problem complicated but what i want is the label is moving vertically when the form is loaded i have try those source code posted by Hack but it still not working.
    Did you set the timer interval to something appropriate?

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    Re: How to make a label move

    the label can move now thanks guy!! , the think is i forgot to put the timer on the form. I have another question whut if after move to the left until it disappear how i want it to start move again from the original place

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Smile Re: How to make a label move

    Have you played with Private, form level variables before? You want to create a variable right at the top of your VB form, like this:
    Code:
    Private m_OriginalLabelPos as integer
    Then in your form_load event (so after to form and it's controls are instanciated and prior to them rendering on screen or the timer starting), to capture the label's start position, and store it within this variable:
    Code:
    Private Sub Form_Load()
        m_OriginalLabelPos = LabelNameHere.left
    End Sub
    That's just gone and stored the original value of the left property position of your label, in a variable which can nowbe accessed from within any sub procedure or function in your form -including that of the timer interval passing Timer1_Timer() event.

    The next stage is to add an IF statement to this event to check whether the label's left position, plus it's width (giving us it's right position), are less than that of the form's left position. If this is the case, the label is appearing "off-screen" and therefore we reset it to it's original position:
    Code:
    Private Sub Timer1_Timer()   
        If CInt(LabelNameHere.left + LabelNameHere.Width) < 85 Then
            LabelNameHere.left = OriginalLabelPos 
        Else
            LabelNameHere.Left= LabelNameHere.left -10
        End If
    End Sub
    Last edited by alex_read; Jul 2nd, 2008 at 01:08 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to make a label move

    The label will be in its original place the next time the form is loaded.

    If you don't want it to move off the form, then use the Form's Left property as the labels maximum -10 left most position.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    selangor, Malaysia
    Posts
    71

    Re: How to make a label move

    i have use alex_read source code but the label stuck
    on the first place, it did not scroll like the first time it moves. When the label disappear on the left i want it to move back again on the right. Am i have to widen the label box?

  14. #14
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: How to make a label move

    I've now bought up VS and tested the coding now. Please try the above ammended and tested sample which should get you up and running.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

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