Can anyone convert this vb.net code to C#?

321 views Asked by At

I'm facing troubles with converting this code ( for using this FFmpeg Wrapper ) to C# since it's the main language of my project .

I tried http://www.developerfusion.com/tools/convert/vb-to-csharp/ but the result code didn't work with me :(

I know it's a newbie request, I'm sorry ;

The Code :

    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
1

There are 1 answers

0
cHao On

C# doesn't have a strict equivalent for the Handles keyword; what you need to do is add event handlers yourself in the constructor.

public Form1() {
    ...

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

You don't need an equivalent for WithEvents, as that just tells VB there are events to be wired up, and in C# you do that yourself.

The rest is a very straightforward translation. A Sub is basically a function with void return type, ByVal and the Handles clauses can go away, keywords are lowercase, and the rest is just semicolons and braces.

For example,

private void ConOut(String prog, String tl) {
    OperationPrgrss.Value = prog;
    Application.DoEvents();
}