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?
Best implementation depends of what you are attempting to do exactly. Nadeem_MK gives you a valid one. Know you can also:
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
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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With