How To Count Button Click In VB.NET

Count Button Click in VB.NET

If You Are Making A Program In Which You Have To Count The Total Number Of Clicks Of A Button And Looking For That Code Then You Are At Right Place :)


Lets Start With Creating A New Project In Visual Studio . Add One TextBox [TextBox1] Which Will Be Used To Display Total Clicks , One Button ( On Clicking It Will Count Total Number Of Clicks )


Code For Counting Total Clicks


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'Code From NarendraDwivedi.Org
        Static Counter
        Counter = Counter + 1
        TextBox1.Text = Counter
    End Sub
        

Output


Add String In Click Count

If You Want To Add (Append) String/Text Along With The Click Count Number Then Firstly You Need To Convert Click Count As String Then Add Your Desired String In It

Code For Adding Custom String or Text With Click Count


   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       'Code From NarendraDwivedi.Org
        Static Counter
        Counter = Counter + 1
        Counter = Str(Counter)
        Dim countit As String = Counter + ("demotext")
        TextBox1.Text = countit
    End Sub
        

Output