如何从其他表格中调用或使用此功能,以便节省时间?
Private Function Working(ByVal move As String, ByVal e As KeyEventArgs) As String
Dim p As Boolean
If e.KeyCode = Keys.W Then
Guy.Location = New Point(Guy.Location.X, Guy.Location.Y - 10)
p = True
End If
Return p
End Function
答案 0 :(得分:0)
'Private'存在的原因是为了防止其他类调用函数。您可以创建函数Public
或Friend
或将其导出到新的类/模块中:
Module Utils
Public Function Working(Guy As Guy) As String
Dim p As Boolean
If e.KeyCode = Keys.W Then
Guy.Location = New Point(Guy.Location.X, Guy.Location.Y - 10)
p = True
End If
Return p
End Function
End Module
并从两种表单中调用Utils.Working
。
答案 1 :(得分:0)
如上所述,private是关于保持子和函数私有的。我不知道在这种特殊情况下这是否有任何意义(我有点怀疑),但是当你做这样的事情时,它经常会这样:
Public Function PublicWorking(ByVal move As String, ByVal e As KeyEventArgs) As String
Dim p as Boolean = Working(move,e)
Return p
End Function
Private Function Working(ByVal move As String, ByVal e As KeyEventArgs) As String
Dim p As Boolean
If e.KeyCode = Keys.W Then
Guy.Location = New Point(Guy.Location.X, Guy.Location.Y - 10)
p = True
End If
Return p
End Function
您可以调用“PublicWorking”功能,该功能将调用Working。
此致
Libor的