首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子类中的RaiseEvent不工作(vb.net)

子类中的RaiseEvent不工作(vb.net)
EN

Stack Overflow用户
提问于 2014-04-15 15:33:20
回答 1查看 1K关注 0票数 1

因此,我有一个带有平数的类来帮助我处理进度栏阶段,一个带有工作子类的子类来完成这项工作,而我有一个带有他自己事件的子类,我刚刚从主类中复制了这个子类。问题是子类中的事件根本不起作用。我不知道为什么真的。

这就是我的代码的样子:

代码语言:javascript
复制
Class FolderHelper

    'Thats my progressbar eventhandler. It is OK
    Private Shared _StageCompleted As Integer

    Public Shared Event MyProgressChanged(ByVal CurStage As Integer)

    Public Shared Property StageCompleted() As Integer
        Get
            Return _StageCompleted
        End Get

        Set(ByVal CurProgress As Integer)
            _StageCompleted = CurStage
            'This event is OK.
            RaiseEvent MyProgressChanged(CurStage)
        End Set
    End Property

    Private Sub RefreshProgress() Handles Me.MyProgressChanged
       'Some progressbar stuff here
    End Sub

    'This is my subclass with malfunction event
    Public Class ParseNames

        Private Shared _FilePath As String

        Public Shared Event NewFilePath(ByVal NewFile As String)

        Public Shared Property FilePath() As String
            Get
                Return _FilePath
            End Get

            Set(ByVal NewFile As String)
                _FilePath = NewFile

                'Problem here. Event doesnt fire. 
                'But its completely copies event in class above.
                RaiseEvent NewFilePath(NewFile)
            End Set
        End Property

        Private Sub AnalyzeNewFile(ByVal NewFile As String) Handles MyClass.NewFilePath
             'Some work here
        End Sub

    End Class

    'class with some work subs...
    Public class DoWorks

        Private Sub DoWork()
            'Thats what has to call a work

             'This variable set is NOT ok with firing event
             Folder_helper.ParseNames.Filepath = SomeNewFile

             'This one IS ok
             Folder_helper.StageCompleted +=1

        End Sub
    End class

End Class

好的。奥斯卡去冥王星:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-22 15:54:15

代码必须像这样才能工作:

代码语言:javascript
复制
Class FolderHelper
'Create an instance of my private class which is listening to events
Public Shared WithEvents PN As New ParseNames

Public Class ParseNames
      'Same strings as above...
End class

'All others strings are the same except...

Public class DoWorks

    Private Sub DoWork()

         'I has to call my newly created instance of ParseNames which is "WithEvents"
         PN.Filepath = SomeNewFile
         Folder_helper.StageCompleted +=1

    End Sub
End class

端级

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23088258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档