Visual Basic 2008 스크롤 텍스트 코드가 있습니까?
문제
Visual Basic 2008에서 텍스트에 적용될 때 화면을 가로 질러 스크롤하는 코드를 원합니다. 나는 화려한 것을 원하지 않습니다. 너희들이 큰 일을 알고 있다면!
편집하다:
나는 그것이 순환하기를 원합니다. 이것이 더 쉬워지기를 바랍니다!
해결책
필요한 것 : 단일 레이블, 이름을 지정할 수 있지만이 경우 레이블 1은 우리의 레이블이며 양식 파일 이름은 form1.vb이지만 물론 이것을 변경할 수 있습니다.
여전히해야 할 일 : 두 경우 모두 텍스트 ScrollLabel (15)을 편집하여 원하는 속도로 만듭니다. 시간은 반복 사이에 밀리 초입니다.
이 작업을 수행하는 더 좋은 방법이있을 수 있지만 여기에 가장 좋은 샷이 있습니다.
Public Class Form1
Dim IsClosed As Boolean = False
Private Sub wait(ByVal time)
Dim sw As New Stopwatch
sw.Start()
Do While sw.ElapsedMilliseconds < time
Application.DoEvents() 'Lets our UI remain active
Loop
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
IsClosed = True
End Sub
Private Sub Form1_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
scrollLabel(15)
End Sub
Private Sub scrollLabel(ByVal time)
Dim passed As Boolean = False 'Indicates whether or not we have passed the initial bounds of the form
Dim startX As Integer = Label1.Bounds.X
For i As Integer = 0 To Me.Bounds.Width + Label1.Bounds.Width Step 1
wait(time)
Label1.SetBounds(Label1.Bounds.X - 1, Label1.Bounds.Y, Label1.Bounds.Width, Label1.Bounds.Height)
If i > Me.Width - startX And passed = False Then
Label1.SetBounds(Me.Width, Label1.Bounds.Y, Label1.Bounds.Width, Label1.Bounds.Height)
passed = True
End If
If IsClosed = True Then
Return
End If
Next
scrollLabel(15)
End Sub
End Class
Isclosed가 응용 프로그램이 종료되면 응용 프로그램이 계속되지 않도록 루프를 깨뜨리는 데 어떻게 도움이되는지 확인하십시오.
또한 스크롤하는 동안 사용자가 양식을 조정 한 경우 왼쪽에 닿을 때 레이블이 점프 될 수 있지만 전체 루프가 완료되면 자체적으로 수정됩니다.
다른 팁
타이머를 사용하면 더 쉽습니다.
Lable.Text = Lable1.Text.Substring(1) & Lable1.Text.Substring(0, 1)
이 코드 타이머를 넣고 양식로드에 시작 타이머를 사용할 수있는 방법입니다.
제휴하지 않습니다 StackOverflow