0

我对编程很陌生,有人告诉我应该使用 ByRef 和 ByVal 传递东西,但是当我这样做时,我收到一条错误消息:

Error   3   Method 'Private Sub Activate_Click(ByRef intIDToChange As Integer, sender As Object, e As System.EventArgs)' 
cannot handle event 'Public Event Click(sender As Object, e As System.EventArgs)' because they do not have a compatible signature.  
F:\Dropbox\Gooby Backup\School Work\Computing\Unit 4\Room Booking Client\WindowsApplication1\ActivateDeactivate\Activate Deactivate.vb  32  129 WindowsApplication1

我开始我的子:

Private Sub Activate_Click(ByRef intIDToChange As Integer, sender As System.Object, e As System.EventArgs) Handles Activate.Click
4

3 回答 3

2

您无法Activate.Click使用您的方法处理,因为您有Integer与事件签名不兼容的附加参数。

事件签名

Click(sender As Object, e As System.EventArgs)

你的方法

Activate_Click(ByRef intIDToChange As Integer, sender As System.Object, e As System.EventArgs)
于 2013-03-26T11:29:02.217 回答
0

听起来您在此处声明的事件处理程序 (Activate_Click) 与 ActivateClick 的事件定义不匹配。

尝试更改为:

Private Sub Activate_Click(ByVal intIDToChange As Integer, ....) Handles Activate.Click

ByVal 通过参数发送变量的值,而 ByRef 发送变量(这意味着子例程中所做的更改会影响调用例程变量)。

更详细的答案在这里: http ://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/07b9d3b9-5658-49ed-9218-005564e8209e/

于 2013-03-26T11:32:37.930 回答
0

您必须将您的方法定义为

Private Sub Activate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Activate.Click

因为按钮点击事件只需要两个参数。

如果您想使用该变量intIDToChange,请将其作为类级别变量提供,例如

private intIDToChange as Integer并在Activate_Click.

于 2013-03-26T11:29:26.090 回答