Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click a button programmatically

I want to code a button that programmatically clicks the other button when I click it.

For example, I have two buttons named Button1 and Button2, what I wanted to do is that immediately after I click Button1, it should click Button2. Is this possible?

like image 243
Marc Intes Avatar asked Oct 03 '13 05:10

Marc Intes


2 Answers

Best implementation depends of what you are attempting to do exactly. Nadeem_MK gives you a valid one. Know you can also:

  1. raise the Button2_Click event using PerformClick() method:

    Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        'do stuff
        Me.Button2.PerformClick()
    End Sub
    
  2. attach the same handler to many buttons:

    Private Sub Button1_Click(sender As Object, e As System.EventArgs) _
        Handles Button1.Click, Button2.Click
        'do stuff
    End Sub
    
  3. call the Button2_Click method using the same arguments than Button1_Click(...) method (IF you need to know which is the sender, for example) :

    Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
        'do stuff
         Button2_Click(sender, e)
    End Sub
    
like image 114
Chris Avatar answered Oct 24 '22 23:10

Chris


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button2_Click(Sender, e)
End Sub

This Code call button click event programmatically

like image 41
senthilkumar2185 Avatar answered Oct 24 '22 21:10

senthilkumar2185