1

我将 ac# 类转换为 vb 网络,但有些事件无法找出这些是代表声明:

    Public Delegate Sub IndentChangedEventHandler(NewValue As Integer)
    Public Delegate Sub MultiIndentChangedEventHandler(LeftIndent As Integer, HangIndent As Integer)
    Public Delegate Sub MarginChangedEventHandler(NewValue As Integer)
    Public Delegate Sub TabChangedEventHandler(args As TabEventArgs)

    Public Event LeftHangingIndentChanging As IndentChangedEventHandler
    Public Event LeftIndentChanging As IndentChangedEventHandler
    Public Event RightIndentChanging As IndentChangedEventHandler
    Public Event BothLeftIndentsChanged As MultiIndentChangedEventHandler

    Public Event LeftMarginChanging As MarginChangedEventHandler
    Public Event RightMarginChanging As MarginChangedEventHandler

    Public Event TabAdded As TabChangedEventHandler
    Public Event TabRemoved As TabChangedEventHandler
    Public Event TabChanged As TabChangedEventHandler

'这是在vb net上转换的函数

Private Sub AddTab(pos As Single)
            Dim rect As New RectangleF(pos, 10.0F, 8.0F, 8.0F)
            tabs.Add(rect)
            If TabAdded IsNot Nothing Then
                TabAdded.Invoke(CreateTabArgs(pos))
            End If
        End Sub

c# 上的句子是

if (TabAdded != null)
                TabAdded.Invoke(CreateTabArgs(pos));

调用代表的正确方法应该是什么?

4

2 回答 2

0

我认为你应该使用Address Of. 方法到委托的转换在 C# 中是隐式的。在 VB.Net 中,它明确地使用,我们使用Address Of. 转换器忘记了这件事。

更多请阅读这里

从 C# 转换为 VB.NET 的代码中出现奇怪错误

VB.NET 中的方法组?

于 2012-11-23T08:04:42.440 回答
0
if (TabAdded != null)
            TabAdded.Invoke(CreateTabArgs(pos));

事件在 vb.net 中有三个访问器:add、remove 和 raise。C# 不支持 raise 访问器,因此您必须显式测试 null。这在 vb.net 中是不必要的,也是不允许的,直接使用 RaiseEvent 语句而不测试 Nothing:

Private Sub AddTab(ByVal pos As Single)
    Dim rect As New RectangleF(pos, 10.0F, 8.0F, 8.0F)
    tabs.Add(rect)
    RaiseEvent TabAdded(CreateTabArgs(pos))
End Sub
于 2012-11-23T11:29:01.590 回答