![]() |
|
[VB6, VB.Net] Marquee Text [All Directions] - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: [VB6, VB.Net] Marquee Text [All Directions] (/Thread-VB6-VB-Net-Marquee-Text-All-Directions) |
[VB6, VB.Net] Marquee Text [All Directions] - Coder-san - 12-02-2010 Here is a Subroutine to make a Marquee effect in desired direction with desired speed. You need a Timer which is enabled with an Interval of about 100 ms, and a Label. Any other control can also be used in place of Label in the VB.Net Marquee Sub. VB.Net Code: Private Sub Marquee(ByVal aCtrl As Control, ByVal Direction As Byte, Optional ByVal Speed As Integer = 3)
Select Case Direction
Case 0 'Leftwards
If aCtrl.Left <= 0 - aCtrl.Width Then
aCtrl.Left = Me.Width
Else
aCtrl.Left = aCtrl.Left - Speed
End If
Case 1 'Rightwards
If aCtrl.Left >= Me.Width Then
aCtrl.Left = 0 - aCtrl.Width
Else
aCtrl.Left = aCtrl.Left + Speed
End If
Case 2 'Upwards
If aCtrl.Top <= 0 - aCtrl.Height Then
aCtrl.Top = Me.Height
Else
aCtrl.Top = aCtrl.Top - Speed
End If
Case 3 'Downwards
If aCtrl.Top >= Me.Height Then
aCtrl.Top = 0 - aCtrl.Height
Else
aCtrl.Top = aCtrl.Top + Speed
End If
End Select
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Marquee(Label1, 0, 3)
End SubVB6 Code: Private Sub Timer1_Timer()
Call Marquee(Label1, 1, 3)
End Sub
Private Sub Marquee(ByVal aLabel As Label, ByVal Direction As Byte, Optional ByVal Speed As Integer = 3)
Me.ScaleMode = 3 'To Scale in Pixels
Select Case Direction
Case 0 'Leftwards
If aLabel.Left <= 0 - aLabel.Width Then
aLabel.Left = Me.ScaleWidth
Else
aLabel.Left = aLabel.Left - Speed
End If
Case 1 'Rightwards
If aLabel.Left >= Me.ScaleWidth Then
aLabel.Left = 0 - aLabel.Width
Else
aLabel.Left = aLabel.Left + Speed
End If
Case 2 'Upwards
If aLabel.Top <= 0 - aLabel.Height Then
aLabel.Top = Me.ScaleHeight
Else
aLabel.Top = aLabel.Top - Speed
End If
Case 3 'Downwards
If aLabel.Top >= Me.ScaleHeight Then
aLabel.Top = 0 - aLabel.Height
Else
aLabel.Top = aLabel.Top + Speed
End If
End Select |