I want to have 60 buttons that each button has same function with other but not the output when its selected/focused. I don't want to make one by one function.

Here is what i mean:

Private Sub Button_Click() Handles button1.click, button2.click, .... ,button60.click
    Dim ST As Button
    [ST As Selected/Focused Button] <-- I have no idea
    ST.BackColor.ToString = TextBox1.Text
End Sub

Edited 4 Years Ago by Dzulham

You need to make use of the sender object.


Private Sub Button_Click(sender as System.Object, e as System.EventArgs)
        Dim ST As New Button

        ST = TryCast(sender,button)

        ST.BackColor.ToString = TextBox1.Text
    End Try
End Sub

Programaticly add this handler to each button ( To rid yourself of the long line of handles clauses )


For Each btn as Button in Me.Controls
   AddHandler btn.Click, AddressOf Button_Click

'Assuming those buttons are the only ones that exist.

Hope this helps.

Edited 4 Years Ago by Begginnerdev

This question has already been answered. Start a new discussion instead.