[RESOLVED]How to make a button click event happen from another sub?
I have a sub procedure that I want to have act like it can click a button to make the button's procedures for the click event fire.
Is there an easy way to do this or should I go about this differently?
Thanks in advance.
Re: How to make a button click event happen from another sub?
Post the code procedures. There are a few different ways. If its from another buttons click
event you can just call the other command buttons event passing the sender and e arguments
from the first buttons received arguments.
Re: How to make a button click event happen from another sub?
VB Code:
Private Sub btnTimeChnge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimeChnge.Click
timerVariable = tbxTimerLength.Text.ToString
tmrLoadPge.Interval = 60000 * timerVariable
End Sub
Was thinking of having the timer call the button click.
But then I realized I could use the timer to loop.
VB Code:
Private Sub tmrLoadPge_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLoadPge.Tick
tmrLoadPge.Stop()
Process.Start(Me.lnkWebPages.Text)
tmrLoadPge.Start()
End Sub
But I would still like to see it the way I originally asked about it.
Thanks in advance.
Re: How to make a button click event happen from another sub?
Something like this should do you:
VB Code:
Private Sub tmrLoadPge_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLoadPge.Tick
tmrLoadPge.Stop()
Process.Start(Me.lnkWebPages.Text)
btnTimeChnge_Click(tmrLoadPge, e)
tmrLoadPge.Start()
End Sub
It's just like calling any other method. You specify the name of the procedure and pass the required arguments. In this case, the object that is calling the event tmrLoadPge and then an event arguments class. The simplest way is to pass the event arguments of the timer event as per the example above.
You could also use
VB Code:
btnTimeChnge_Click(tmrLoadPge, New EventArgs)
This passes a new instance of the basic eventargs class.
Some events have other types of eventargs classes associated with them so you may find things like calling a keypress event from code a little more complex, but here you're just fine with the default class.
Hope this is what you're looking for. :D
Re: How to make a button click event happen from another sub?
Hi,
Or
Button1.PerformClick()
Re: How to make a button click event happen from another sub?
Oh yeah....forgot that simple one....
Always looking for the complicated answer :blush: :blush:
Re: How to make a button click event happen from another sub?
LOL, awesome guys. Thanks. I will try to understand the passing of arguments by playing with your sample too.
Thanks again.