Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arguments to use when calling an Event

Status
Not open for further replies.

KLK000

MIS
May 22, 2002
37
US
If I need to call an event from code, say a button click event, what arguments do I use for the sender and e arguments?

Private Sub btnDoSomething_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoSometing.Click
do something code here
End sub

Private sub MySub()
me.btnDoSomething_Click(ss, ee)
End Sub

What do I put in place of ss and ee?

Or is there a better way to trigger the btnDoSomething_Click event from code?

Thanks.
 
I would move the contents of the button click event to it's own method. That way you can call it from the button, or from your own code, without worrying about what to pass.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Now why didn't I think of that? Sometimes I feel I should just give up.

Thanks!
 
Definitely chiph's suggestion is the way to go. But if you want you can trigger an event like this

Code:
me.btnDoSomething_Click(nothing, nothing)

provided you are not referencing the event arguments.

-Kris
 
Thanks Kris. While experimenting I tried using the (nothing, nothing) arguments and it worked. However, for some reason I felt uncomfortable doing it. But now that you mention it, I'm not using the event arguments (sender, e) in the btnDoSomething_Click event so I shouldn't be concerned...

For now, I'll move the code to a separate sub.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top