0

我有这个类,将委托定义为函数

<br />

using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.ComponentModel;<br />
using System.Collections;<br /><br />
namespace ClassLibrary1<br />
{<br />
    public delegate bool DrillDownHandler(IComponent control);<br />
    public delegate void ComponentLoadedHandler(IComponent control);

        public interface interface1
    {
        event DrillDownHandler DrillDown;
        event ComponentLoadedHandler ComponentLoaded;
    }


    public class Class1 : interface1
    {
        public Class1()
        {
            DrillDown += new DrillDownHandler(DrillDownDefault);
        }

        private ArrayList drillList = new ArrayList();
        public event DrillDownHandler DrillDown
        {
            add
            {
                drillList.Add(value);
            }
            remove
            {
                drillList.Remove(value);
            }
        }
        public event ComponentLoadedHandler ComponentLoaded;

        private bool DrillDownDefault(IComponent control)
        {
            return false;
        }
    }
}

当转换为 VB.Net 时,我们得到以下代码,但不起作用

<br /><br />
Imports System<br />
Imports System.Collections.Generic<br />
Imports System.Linq<br />
Imports System.Text<br />
Imports System.ComponentModel<br />
Imports System.Collections<br />
<br />
Namespace ClassLibrary1<br />
    Public Delegate Function DrillDownHandler(control As IComponent) As Boolean<br />
    Public Delegate Sub ComponentLoadedHandler(control As IComponent)<br />


    Public Interface interface1
        Event DrillDown As DrillDownHandler
        Event ComponentLoaded As ComponentLoadedHandler
    End Interface


    Public Class Class1
        Inherits interface1
        Public Sub New()
            DrillDown += New DrillDownHandler(DrillDownDefault)
        End Sub

        Private drillList As New ArrayList()
        Public Custom Event DrillDown As DrillDownHandler
            AddHandler(ByVal value As DrillDownHandler)
                drillList.Add(value)
            End AddHandler
            RemoveHandler(ByVal value As DrillDownHandler)
                drillList.Remove(value)
            End RemoveHandler
        End Event
        Public Event ComponentLoaded As ComponentLoadedHandler

        Private Function DrillDownDefault(control As IComponent) As Boolean
            Return False
        End Function
    End Class
End Namespace

任何人都可以提供帮助

4

1 回答 1

1

在 VB.Net 中,不能使用具有返回类型的委托来声明事件。只有具有子“代表”的事件是可能的。改为使用带有“ByRef”参数的“Sub”委托。

Public Delegate Sub DrillDownHandler(control As IComponent, ByRef bReturnVal As Boolean)

欲了解更多信息,请访问http://social.msdn.microsoft.com/Forums/en/vblanguage/thread/f1141545-6ef5-49df-8c16-ad27ee41a3bc

希望它应该工作。

于 2012-09-08T06:34:58.000 回答