2011年11月6日 星期日

#VB PerformClick 與 _Click

PerformClick() doesn't work
http://www.vbforums.com/showthread.php?t=640015

If you're going to call the other button's click event sub directly, the least you could do is pass it the proper params instead of two Nothing's (in case sender is actually used in the event sub itself):
vb.net Code:
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.     Button2_Click(Button2, EventArgs.Empty)
  3. End Sub
  4.  
  5. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  6.     MsgBox("Hello")
  7. End Sub

But ideally, you should never need to use a Button's PerformClick() method nor should you need to call an event's sub directly either, the code should be placed in it's own sub (accepting the needed params) and called from the multiple places that it's needed.

沒有留言:

張貼留言