如何实现我用Public Subs创建的自定义DLL

时间:2018-11-26 20:46:29

标签: vb.net visual-studio visual-studio-2017

我正在制作自己的游戏,我想实现自己制作的自定义DLL。它使用自定义的Public Sub参数,似乎无法正确实现。 DLL的代码如下:

Public Class EventChanger
    Public Sub StopEvent()
        'code here to stop event
    End Sub
    Public Sub StartEvent()
        'code here to start event
    End Sub
End Class

我对其进行了编译,并添加了对它的引用,并向其中添加了代码。

Imports EventChanger

当我编写代码时,它看起来像这样:

Imports EventChanger
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        EventChanger.EventChanger.StopEvent()
        'other code
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'other code unrelated to event
    End Sub
End Class

我收到这样的错误,所以我尝试了:

Imports EventChanger

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        EventChanger.StopEvent()
        'other code
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'other code unrelated to event
    End Sub
End Class

但是我仍然得到一个错误。有人可以帮我吗?谢谢!

1 个答案:

答案 0 :(得分:1)

将代码更改为

Public Class EventChanger
    Public Shared Sub StopEvent()
        'code here to stop event
    End Sub
    Public Shared Sub StartEvent()
        'code here to start event
    End Sub
End Class

有效。现在,我可以执行以下代码:

Imports EventChanger

And when I make the code it looks like this:

    Imports EventChanger
    Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        EventChanger.EventChanger.StopEvent()
        'other code
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'other code unrelated to event
    End Sub
End Class

这对我有用。