Re: How to make a label move
vb Code:
Private Sub ChangePosition_Click()
Label1.Left = Label1.Left + 100 ' or just place ur own value like label1.left = 500
Label1.Top = Label1.Top + 100 ' or just place ur own value like label1.top = 500
End Sub
that will do the work !!
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
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
Re: How to make a label move
are we did not call timer in sub form_load?
Re: How to make a label move
do u mean to move.......... from Title.............. ??
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.
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.
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?
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
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
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.
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?
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.