我正在尝试创建一个程序,类似于打开程序时弹出的启动提示。我为要显示的文本创建了一个标签,第一个字符串可以正常工作,但是如果我添加其余部分,则最后一个字符串会覆盖所有标签中的前一个.Below是我的代码。
Public Class Form1
Dim string1 As String = "Hello "
Dim string2 As String = "world"
Dim string3 As String = "next text"
Dim string4 As String = "text4"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
lblDisplay.Text = string1
lblDisplay.Text = string2
End Sub
End Class
答案 0 :(得分:1)
单击按钮时将显示每个字符串。它从文本中创建一个String数组string1
,然后当单击该按钮时,它会显示数组中的每个项目,同时跟踪tipcnt
中的项目计数。如果tipcnt
= string1.Count
,它会重置为0.如果要显示更多字符串,只需将它们附加到数组中。
Public Class Form1
Dim string1 As String() = {"Hello", "world", "next text", "text4"}
Dim tipcnt As Integer = 0
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
lblDisplay.Text = string1(tipcnt)
tipcnt += 1
If tipcnt = string1.Count Then tipcnt = 0
End Sub
End Class