Noppy
Noppy

Reputation: 1

How do I make a button perform multiple clicks with one label

I am trying to make a program similar to the startup tips which pop up when you open a program.I created a label for the text to be displayed,first string works but if I add the rest the last string overwrites all the previous ones in the label.Below is my code.

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

Upvotes: 0

Views: 35

Answers (1)

Chase Rocker
Chase Rocker

Reputation: 1908

This will display each string as you click the button. It creates a String array string1 from the text then as the button is clicked, it displays each item in the array while keeping track of the item count in tipcnt. If tipcnt = string1.Count, it resets back to 0. If you have more strings to display, just append them to the array.

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

Upvotes: 1

Related Questions