|
-
Feb 7th, 2011, 02:14 PM
#1
Thread Starter
PowerPoster
[RESOLVED] button click
It was pretty simple in VB6 to invoke the 'click' event of a command button (i.e.; btnNext_Click).
I am having difficulty trying to do the same think in VS2008.
I am getting errors at line btnNext_Click():
Error 1 Argument not specified for parameter 'e' of 'Private Sub btnNext_Click(sender As Object, e As System.EventArgs)'.
Error 2 Argument not specified for parameter 'sender' of 'Private Sub btnNext_Click(sender As Object, e As System.EventArgs)'.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Feb 7th, 2011, 02:57 PM
#2
Re: button click
in vb.net the signature of your event procedure should match.
The easiest way is to let visual studio generate the procedure. For that you do it just as you do in VB6. Either double-click the button in designer, which will generate the default method (click) signature, or select your button name from left dropdown in code window and "Click" from the right dropdown.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Alternatively, you can type this yourself, but then be careful about it; you may do it wrong.
-
Feb 7th, 2011, 03:08 PM
#3
Re: button click
If you are calling the button click handler directly, it requires those two arguments. The sender argument holds the button that raised the event, and the e argument, in the case of a button click, holds nothing useful at all. Therefore, you could call it with:
btnNext_Click(Nothing,Nothing)
but that's not necessarily a good idea. If the sub is using either of those arguments (it is unlikely to be using e in the button click, but sender is possible), then this will most likely cause a crash.
The more typical solution to this would be to make a new sub that has all the code from the click event handler, and have the click event handler call this sub, as well as anything else that needs to call it. That way you are getting just the arguments you need, rather than those mandated by the event. You could also look into PerformClick.
My usual boring signature: Nothing
 
-
Feb 7th, 2011, 03:12 PM
#4
Thread Starter
PowerPoster
Re: button click
The performClick seems to be acceptable to it. Thanks a bunch!
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Feb 7th, 2011, 03:40 PM
#5
Re: button click
 Originally Posted by Pasvorto
The performClick seems to be acceptable to it. Thanks a bunch!
Don't use PerformClick if you want to be happy unless you know fully about it.
It doesn't fire in all cases.
The better surer way is to either move your code into a different procedure and call it from both locations or use Button1_Click(Nothing,Nothing). The former way being the better of the two.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|