0

我在将此代码(用于使用此FFmpeg Wrapper)转换为 C# 时遇到了麻烦,因为它是我项目的主要语言。

我试过http://www.developerfusion.com/tools/convert/vb-to-csharp/ 但结果代码对我不起作用:(

我知道这是一个新手请求,对不起;

编码 :

    Public WithEvents MediaConverter As New FFLib.Encoder

    Private Sub ConOut(ByVal prog As String, ByVal tl As String) Handles MediaConverter.Progress
        OperationPrgrss.Value = prog
        Application.DoEvents()
    End Sub

    Private Sub stat(ByVal status) Handles MediaConverter.Status
        StatusLbl.Text = status
        Application.DoEvents()
    End Sub
4

1 回答 1

1

C# 没有严格等效的Handles关键字;您需要做的是自己在构造函数中添加事件处理程序。

public Form1() {
    ...

    // wire up events
    MediaConverter.Progress += ConOut;
    MediaConverter.Status += stat;
}

您不需要等效的 for WithEvents,因为它只是告诉 VB 有要连接的事件,而在 C# 中您可以自己完成。

其余的是一个非常简单的翻译。ASub基本上是一个有void返回类型的函数ByValHandles子句可以走开,关键字是小写的,剩下的就是分号和大括号。

例如,

private void ConOut(String prog, String tl) {
    OperationPrgrss.Value = prog;
    Application.DoEvents();
}
于 2013-03-10T20:59:28.110 回答