是否有任何 Visual Basic 2008 滚动文本代码? [英] Is there any Visual Basic 2008 scrolling text code?

查看:42
本文介绍了是否有任何 Visual Basic 2008 滚动文本代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个代码,当它应用于 Visual Basic 2008 中的文本时,它会在屏幕上滚动.我不想要任何华而不实的东西,只是一些基本的开始.如果你们知道这样的事情就太好了!

I want a code that when applied to text in Visual Basic 2008 it scrolls across the screen. I don't want anything flashy, just something basic to start off with. If you guys know of such a thing that would be great!

我想让它循环,希望这能让它更容易!

I would like it to cycle, hope this makes it easier!

推荐答案

你需要的是:单个标签,你可以任意命名,但在这种情况下 Label1 是我们的标签,表单文件名为 Form1.vb 但属于当然你可以改变这个.

What you need: A single label, you can name it anything but in this case Label1 is our label, and the form file name is Form1.vb but of course you can change this.

您仍然需要做的:在两种情况下编辑文本 scrollLabel(15) 以使其达到您想要的速度.迭代之间的时间以毫秒为单位.

What you still have to do: Edit the text scrollLabel(15) in both cases to make it the speed you want. The time is in milliseconds, between iterations.

可能有更好的方法来做到这一点,但这是我最好的选择:

There is probably a better way to do this, but here is my best shot:

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 如何帮助打破循环以确保应用程序在关闭后不会继续运行.

Notice how IsClosed helps to break the loop to ensure the application does not continue once it is shut.

此外,如果用户在滚动时调整了表单的大小,则可能会导致标签在点击左侧时跳转,但一旦完成完整循环,就会自行纠正.

Also, if the user has resized the form while it is scrolling it may cause the label to jump when it hits the left side, but that will correct itself once it has completed a full loop.

这篇关于是否有任何 Visual Basic 2008 滚动文本代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆