VB.Net Add Action To All Buttons

How To Add Action To All Buttons In The Form Using Visual Basic.Net

add action to all buttons in vb.net



In this VB.Net Tutorial we will see How To Create A Click Action Event And Set It To All The Buttons Inside A Window Application Form In Visual Basic.Net Programming Language And Visual Studio IDE .




Project Source Code:

Public Class AddEventClickToAllButtons

    
    Private Sub AddEventClickToAllButtons_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        For Each c As Control In Controls

            If c.GetType() = GetType(Button) Then

                AddHandler c.Click, AddressOf btn_Click

            End If

        Next

    End Sub

    Private Sub btn_Click(sender As Object, e As EventArgs)

        Dim btn As Button = sender
        label1.Text = btn.Text

    End Sub

End Class                                       

////// OUTPUT : 

add event click to all buttons using vbnet



Share this

Related Posts

Previous
Next Post »